AspireAzureEFCoreCosmosExtensions Methods
Class Methods 3 members
Extension methods for configuring EntityFrameworkCore DbContext to Azure Cosmos DB
AddCosmosDbContext(IHostApplicationBuilder, string, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>) Section titled AddCosmosDbContext(IHostApplicationBuilder, string, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>) extension Registers the given
EntityFrameworkCore.DbContext as a service in the services provided by the builder. Derives the name of the database from the connection string. public static class AspireAzureEFCoreCosmosExtensions{ public static void AddCosmosDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, Action<EntityFrameworkCoreCosmosSettings>? configureSettings = null, Action<DbContextOptionsBuilder>? configureDbContextOptions = null) { // ... }}Parameters
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to. connectionName string A name used to retrieve the connection string from the ConnectionStrings configuration section. configureSettings Action<EntityFrameworkCoreCosmosSettings> optional An optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration. configureDbContextOptions Action<DbContextOptionsBuilder> optional An optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context. Exceptions
ArgumentNullException Thrown if mandatory builder is null. InvalidOperationException Thrown when mandatory EntityFrameworkCoreCosmosSettings.ConnectionString is not provided. AddCosmosDbContext(IHostApplicationBuilder, string, string, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>) Section titled AddCosmosDbContext(IHostApplicationBuilder, string, string, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>) extension Registers the given
EntityFrameworkCore.DbContext as a service in the services provided by the builder. Enables db context pooling, logging and telemetry. public static class AspireAzureEFCoreCosmosExtensions{ public static void AddCosmosDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, string databaseName, Action<EntityFrameworkCoreCosmosSettings>? configureSettings = null, Action<DbContextOptionsBuilder>? configureDbContextOptions = null) { // ... }}Parameters
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to. connectionName string A name used to retrieve the connection string from the ConnectionStrings configuration section. databaseName string The name of the database to use within the Azure Cosmos DB account. configureSettings Action<EntityFrameworkCoreCosmosSettings> optional An optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration. configureDbContextOptions Action<DbContextOptionsBuilder> optional An optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context. Exceptions
ArgumentNullException Thrown if mandatory builder is null. InvalidOperationException Thrown when mandatory EntityFrameworkCoreCosmosSettings.ConnectionString is not provided. EnrichCosmosDbContext(IHostApplicationBuilder, Action<EntityFrameworkCoreCosmosSettings>) Section titled EnrichCosmosDbContext(IHostApplicationBuilder, Action<EntityFrameworkCoreCosmosSettings>) extension Configures logging and telemetry for the
EntityFrameworkCore.DbContext. public static class AspireAzureEFCoreCosmosExtensions{ public static void EnrichCosmosDbContext<TContext>( this IHostApplicationBuilder builder, Action<EntityFrameworkCoreCosmosSettings>? configureSettings = null) { // ... }}Parameters
builder IHostApplicationBuilder configureSettings Action<EntityFrameworkCoreCosmosSettings> optional Exceptions
ArgumentNullException Thrown if mandatory builder is null. InvalidOperationException Thrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.