AspireEFMySqlExtensions Methods
ClassMethods2 members
Provides extension methods for registering a MySQL database context in an Aspire application.
AddMySqlDbContext(IHostApplicationBuilder, string, Action<PomeloEntityFrameworkCoreMySqlSettings>, Action<DbContextOptionsBuilder>)Section titled AddMySqlDbContext(IHostApplicationBuilder, string, Action<PomeloEntityFrameworkCoreMySqlSettings>, Action<DbContextOptionsBuilder>)extension Registers the given
EntityFrameworkCore.DbContext as a service in the services provided by the builder. Enables db context pooling, retries, corresponding health check, logging and telemetry. public static class AspireEFMySqlExtensions{ public static void AddMySqlDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, Action<PomeloEntityFrameworkCoreMySqlSettings>? 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.configureSettingsAction<PomeloEntityFrameworkCoreMySqlSettings>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 PomeloEntityFrameworkCoreMySqlSettings.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 DbContext.OnConfiguring method can then be overridden to configure EntityFrameworkCore.DbContext options.
EnrichMySqlDbContext(IHostApplicationBuilder, Action<PomeloEntityFrameworkCoreMySqlSettings>)Section titled EnrichMySqlDbContext(IHostApplicationBuilder, Action<PomeloEntityFrameworkCoreMySqlSettings>)extension Configures retries, health check, logging and telemetry for the
EntityFrameworkCore.DbContext. public static class AspireEFMySqlExtensions{ public static void EnrichMySqlDbContext<TContext>( this IHostApplicationBuilder builder, Action<PomeloEntityFrameworkCoreMySqlSettings>? configureSettings = null) { // ... }}Parameters
builderIHostApplicationBuilderconfigureSettingsAction<PomeloEntityFrameworkCoreMySqlSettings>optionalExceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.