AspireEFMySqlExtensions.AddMySqlDbContext<TContext> Method

Definition

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

public static void AddMySqlDbContext<TContext> (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.Pomelo.EntityFrameworkCore.MySql.PomeloEntityFrameworkCoreMySqlSettings>? configureSettings = default, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? configureDbContextOptions = default) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddMySqlDbContext : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Pomelo.EntityFrameworkCore.MySql.PomeloEntityFrameworkCoreMySqlSettings> * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> -> unit (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Sub AddMySqlDbContext(Of TContext As DbContext) (builder As IHostApplicationBuilder, connectionName As String, Optional configureSettings As Action(Of PomeloEntityFrameworkCoreMySqlSettings) = 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<PomeloEntityFrameworkCoreMySqlSettings>

An optional delegate that can be used for customizing options. 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.

Remarks

Reads the configuration from "Aspire:Pomelo:EntityFrameworkCore:MySql:{typeof(TContext).Name}" config section, or "Aspire:Pomelo:EntityFrameworkCore:MySql" if former does not exist.

The OnConfiguring(DbContextOptionsBuilder) method can then be overridden to configure DbContext options.

Applies to