AspireAzureEFCoreCosmosExtensions.AddCosmosDbContext Method

Definition

Overloads

AddCosmosDbContext<TContext>(IHostApplicationBuilder, String, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>)

Registers the given DbContext as a service in the services provided by the builder. Derives the name of the database from the connection string.

AddCosmosDbContext<TContext>(IHostApplicationBuilder, String, String, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>)

Registers the given DbContext as a service in the services provided by the builder. Enables db context pooling, logging and telemetry.

AddCosmosDbContext<TContext>(IHostApplicationBuilder, String, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>)

Source:
AspireAzureEFCoreCosmosExtensions.cs
Source:
AspireAzureEFCoreCosmosExtensions.cs

Registers the given DbContext as a service in the services provided by the builder. Derives the name of the database from the connection string.

public static void AddCosmosDbContext<TContext>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.Microsoft.EntityFrameworkCore.Cosmos.EntityFrameworkCoreCosmosSettings>? configureSettings = default, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? configureDbContextOptions = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddCosmosDbContext : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Microsoft.EntityFrameworkCore.Cosmos.EntityFrameworkCoreCosmosSettings> * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> -> unit (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Sub AddCosmosDbContext(Of TContext As DbContext) (builder As IHostApplicationBuilder, connectionName As String, Optional configureSettings As Action(Of EntityFrameworkCoreCosmosSettings) = Nothing, Optional configureDbContextOptions As Action(Of DbContextOptionsBuilder) = Nothing)

Type Parameters

TContext

The DbContext that needs to be registered.

Parameters

builder
IHostApplicationBuilder

The 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>

An optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration.

configureDbContextOptions
Action<DbContextOptionsBuilder>

An optional delegate to configure the DbContextOptions for the context.

Exceptions

Thrown if mandatory builder is null.

Thrown when mandatory ConnectionString is not provided.

Applies to

AddCosmosDbContext<TContext>(IHostApplicationBuilder, String, String, Action<EntityFrameworkCoreCosmosSettings>, Action<DbContextOptionsBuilder>)

Source:
AspireAzureEFCoreCosmosExtensions.cs
Source:
AspireAzureEFCoreCosmosExtensions.cs
Source:
AspireAzureEFCoreCosmosExtensions.cs
Source:
AspireAzureEFCoreCosmosExtensions.cs
Source:
AspireAzureEFCoreCosmosExtensions.cs

Registers the given DbContext as a service in the services provided by the builder. Enables db context pooling, logging and telemetry.

public static void AddCosmosDbContext<TContext>(this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, string databaseName, Action<Aspire.Microsoft.EntityFrameworkCore.Cosmos.EntityFrameworkCoreCosmosSettings>? configureSettings = default, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? configureDbContextOptions = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddCosmosDbContext : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * string * Action<Aspire.Microsoft.EntityFrameworkCore.Cosmos.EntityFrameworkCoreCosmosSettings> * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> -> unit (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Sub AddCosmosDbContext(Of TContext As DbContext) (builder As IHostApplicationBuilder, connectionName As String, databaseName As String, Optional configureSettings As Action(Of EntityFrameworkCoreCosmosSettings) = Nothing, Optional configureDbContextOptions As Action(Of DbContextOptionsBuilder) = Nothing)

Type Parameters

TContext

The DbContext that needs to be registered.

Parameters

builder
IHostApplicationBuilder

The 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>

An optional delegate that can be used for customizing settings. It's invoked after the settings are read from the configuration.

configureDbContextOptions
Action<DbContextOptionsBuilder>

An optional delegate to configure the DbContextOptions for the context.

Exceptions

Thrown if mandatory builder is null.

Thrown when mandatory ConnectionString is not provided.

Applies to