AspireMongoDBEntityFrameworkCoreExtensions Methods
ClassMethods2 members
Extension methods for configuring EntityFrameworkCore DbContext to a MongoDB database
AddMongoDbContext(IHostApplicationBuilder, string, string?, Action<MongoDBEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>)Section titled AddMongoDbContext(IHostApplicationBuilder, string, string?, Action<MongoDBEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>)extension Registers the given
EntityFrameworkCore.DbContext as a service in the services provided by the builder. Enables db context pooling, retries, health check, logging and telemetry for the EntityFrameworkCore.DbContext. public static class AspireMongoDBEntityFrameworkCoreExtensions{ public static void AddMongoDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, string? databaseName = null, Action<MongoDBEntityFrameworkCoreSettings>? configureSettings = null, Action<DbContextOptionsBuilder>? configureDbContextOptions = null) { // ... }}Parameters
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.databaseNamestring?optionalThe name of the database. If not provided, it will be extracted from the connection string or settings.configureSettingsAction<MongoDBEntityFrameworkCoreSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.configureDbContextOptionsAction<DbContextOptionsBuilder>optionalAn optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context.Exceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory MongoDBEntityFrameworkCoreSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:MongoDB:EntityFrameworkCore:{typeof(TContext).Name}" config section, or "Aspire:MongoDB:EntityFrameworkCore" if former does not exist.
EnrichMongoDbContext(IHostApplicationBuilder, Action<MongoDBEntityFrameworkCoreSettings>)Section titled EnrichMongoDbContext(IHostApplicationBuilder, Action<MongoDBEntityFrameworkCoreSettings>)extension Configures logging and telemetry for the
EntityFrameworkCore.DbContext. public static class AspireMongoDBEntityFrameworkCoreExtensions{ public static void EnrichMongoDbContext<TContext>( this IHostApplicationBuilder builder, Action<MongoDBEntityFrameworkCoreSettings>? configureSettings = null) { // ... }}Parameters
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.configureSettingsAction<MongoDBEntityFrameworkCoreSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.Exceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.Remarks
Reads the configuration from "Aspire:MongoDB:EntityFrameworkCore:{typeof(TContext).Name}" config section, or "Aspire:MongoDB:EntityFrameworkCore" if former does not exist.