AspireSqlServerEFCoreSqlClientExtensions Methods
ClassMethods2 members
Extension methods for configuring EntityFrameworkCore DbContext to Azure SQL, MS SQL server
AddSqlServerDbContext(IHostApplicationBuilder, string, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>, Action<DbContextOptionsBuilder>)Section titled AddSqlServerDbContext(IHostApplicationBuilder, string, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>, Action<DbContextOptionsBuilder>)extension Registers the given
EntityFrameworkCore.DbContext as a service in the services provided by the builder. Enables db context pooling, retries, health check, logging and telemetry for the EntityFrameworkCore.DbContext. public static class AspireSqlServerEFCoreSqlClientExtensions{ public static void AddSqlServerDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>? 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<MicrosoftEntityFrameworkCoreSqlServerSettings>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 MicrosoftEntityFrameworkCoreSqlServerSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:Microsoft:EntityFrameworkCore:SqlServer:{typeof(TContext).Name}" config section, or "Aspire:Microsoft:EntityFrameworkCore:SqlServer" if former does not exist.
EnrichSqlServerDbContext(IHostApplicationBuilder, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>)Section titled EnrichSqlServerDbContext(IHostApplicationBuilder, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>)extension Configures retries, health check, logging and telemetry for the
EntityFrameworkCore.DbContext. public static class AspireSqlServerEFCoreSqlClientExtensions{ public static void EnrichSqlServerDbContext<TContext>( this IHostApplicationBuilder builder, Action<MicrosoftEntityFrameworkCoreSqlServerSettings>? configureSettings = null) { // ... }}Parameters
builderIHostApplicationBuilderconfigureSettingsAction<MicrosoftEntityFrameworkCoreSqlServerSettings>optionalExceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.