Method AddMongoDB
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- MongoDB.EntityFrameworkCore.dll
AddMongoDB<TContext>(IServiceCollection, string, string, Action<MongoDbContextOptionsBuilder>?, Action<DbContextOptionsBuilder>?)
Registers the given Entity Framework DbContext as a service in the IServiceCollection and configures it to connect to an MongoDB database.
public static IServiceCollection AddMongoDB<TContext>(this IServiceCollection serviceCollection, string connectionString, string databaseName, Action<MongoDbContextOptionsBuilder>? mongoOptionsAction = null, Action<DbContextOptionsBuilder>? optionsAction = null) where TContext : DbContext
Parameters
serviceCollectionIServiceCollectionThe IServiceCollection to add services to.
connectionStringstringThe connection string of the MongoDB server to connect to.
databaseNamestringThe database name on the server.
mongoOptionsActionAction<MongoDbContextOptionsBuilder>An optional action to allow additional MongoDB-specific configuration.
optionsActionAction<DbContextOptionsBuilder>An optional action to configure the DbContextOptions for the context.
Returns
- IServiceCollection
The same service collection so that multiple calls can be chained.
Type Parameters
TContextThe type of context to be registered.
AddMongoDB<TContext>(IServiceCollection, IMongoClient, string, Action<MongoDbContextOptionsBuilder>?, Action<DbContextOptionsBuilder>?)
Registers the given Entity Framework DbContext as a service in the IServiceCollection and configures it to connect to an MongoDB database.
public static IServiceCollection AddMongoDB<TContext>(this IServiceCollection serviceCollection, IMongoClient mongoClient, string databaseName, Action<MongoDbContextOptionsBuilder>? mongoOptionsAction = null, Action<DbContextOptionsBuilder>? optionsAction = null) where TContext : DbContext
Parameters
serviceCollectionIServiceCollectionThe IServiceCollection to add services to.
mongoClientIMongoClientThe MongoDB.Driver.IMongoClient to use to connect to the MongoDB server.
databaseNamestringThe database name on the server.
mongoOptionsActionAction<MongoDbContextOptionsBuilder>An optional action to allow additional MongoDB-specific configuration.
optionsActionAction<DbContextOptionsBuilder>An optional action to configure the DbContextOptions for the context.
Returns
- IServiceCollection
The same service collection so that multiple calls can be chained.
Type Parameters
TContextThe type of context to be registered.