AspireEFPostgreSqlExtensions Methods
ClassMethods2 members
Provides extension methods for registering a PostgreSQL database context in an Aspire application.
AddNpgsqlDbContext(IHostApplicationBuilder, string, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>, Action<DbContextOptionsBuilder>) Section titled AddNpgsqlDbContext(IHostApplicationBuilder, string, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>, 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 AspireEFPostgreSqlExtensions{ public static void AddNpgsqlDbContext<TContext>( this IHostApplicationBuilder builder, string connectionName, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>? configureSettings = null, Action<DbContextOptionsBuilder>? configureDbContextOptions = null) { // ... }}Parameters
builderIHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to.connectionName stringA name used to retrieve the connection string from the ConnectionStrings configuration section.configureSettings Action<NpgsqlEntityFrameworkCorePostgreSQLSettings> optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.configureDbContextOptions Action<DbContextOptionsBuilder> optionalAn optional delegate to configure the EntityFrameworkCore.DbContextOptions for the context.Exceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory NpgsqlEntityFrameworkCorePostgreSQLSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{typeof(TContext).Name}" config section, or "Aspire:Npgsql:EntityFrameworkCore:PostgreSQL" if former does not exist.
The Db method can then be overridden to configure Entity options.
EnrichNpgsqlDbContext(IHostApplicationBuilder, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>) Section titled EnrichNpgsqlDbContext(IHostApplicationBuilder, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>)extension Configures retries, health check, logging and telemetry for the
EntityFrameworkCore.DbContext . public static class AspireEFPostgreSqlExtensions{ public static void EnrichNpgsqlDbContext<TContext>( this IHostApplicationBuilder builder, Action<NpgsqlEntityFrameworkCorePostgreSQLSettings>? configureSettings = null) { // ... }}Parameters
builderIHostApplicationBuilder configureSettings Action<NpgsqlEntityFrameworkCorePostgreSQLSettings> optionalExceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory EntityFrameworkCore.DbContext is not registered in DI.