Skip to content
DocsTry Aspire
DocsTry

AspireAzureEFCoreCosmosExtensions Methods

ClassMethods3 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)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<EntityFrameworkCoreCosmosSettings>optionalAn optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration.
configureDbContextOptionsAction<DbContextOptionsBuilder>optionalAn optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context.
ArgumentNullExceptionThrown if mandatory builder is null.
InvalidOperationExceptionThrown 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)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
databaseNamestringThe name of the database to use within the Azure Cosmos DB account.
configureSettingsAction<EntityFrameworkCoreCosmosSettings>optionalAn optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration.
configureDbContextOptionsAction<DbContextOptionsBuilder>optionalAn optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context.
ArgumentNullExceptionThrown if mandatory builder is null.
InvalidOperationExceptionThrown 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)
{
// ...
}
}
builderIHostApplicationBuilder
configureSettingsAction<EntityFrameworkCoreCosmosSettings>optional
ArgumentNullExceptionThrown if mandatory builder is null.
InvalidOperationExceptionThrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.