Skip to content

MongoDb

ZhangYang edited this page Sep 7, 2019 · 2 revisions

Integrate MongoDb read model

Integrating MongoDb is quite simple, install nuget MongoDB.Driver and EventFlow.MongoDB. The registration as below, ideally the connection string should come from Configuration, but these is no chance to inject IConfiguration in this design, I'd suggest EventFlow can add IMongoClientProvider to config connection string

public class MongoDbReadModelModule : IModule
{
    public void Register(IEventFlowOptions eventFlowOptions)
    {
        // TODO: read form config
        var client = new MongoClient("mongodb://localhost:27017");

        eventFlowOptions
            .AddDefaults(typeof(MongoDbReadModelModule).Assembly)
            .ConfigureMongoDb(client, "restairline")
            .UseMongoDbReadModel<MongoDbBookingReadModel>();
    }
}

For testing we used Mongo2Go, please take a look at RestAirline.ReadModel.MongoDB.Tests How tests work.

Clone this wiki locally