Wrapper for the C# MongoDB Driver to provide easier methods of generating a context to work with, in addition to providing automation around Collection names
- Reference the project in your existing project
MongoDbProvider.Interfaces.IDatabaseOptionsis given to provide a template for the connection details- Call the Context as shown below:
using MongoDbProvider.Interfaces;
using MongoDB.Driver;
// ...
private readonly IMongoCollection<Model> collection;
// Ctor (IDatabaseOptions options)
{
collection = new ContextProvider<Model>(options).Context;
}
// ...
// Method - InsertOne(Model model)
{
// Validation and other logic etc.
await collection.InsertOneAsync(model);
}The CollectionName will be a pluralized version of the <T> model, eg. given <T> is a class TestModel then the collection name would appear as TestModels
For a working example of implementation see the included Tests code
- MongoDB.Driver
- PluralizeService.Core
Will Blackburn - Harkole