AspirePostgreSqlNpgsqlExtensions Methods
ClassMethods2 members
Extension methods for connecting PostgreSQL database with Npgsql client
AddKeyedNpgsqlDataSource(IHostApplicationBuilder, string, Action<NpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)Section titled AddKeyedNpgsqlDataSource(IHostApplicationBuilder, string, Action<NpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)extension Registers
NpgsqlDataSource as a keyed service for given name for connecting PostgreSQL database with Npgsql client. Configures health check, logging and telemetry for the Npgsql client. public static class AspirePostgreSqlNpgsqlExtensions{ public static void AddKeyedNpgsqlDataSource( this IHostApplicationBuilder builder, string name, Action<NpgsqlSettings>? configureSettings = null, Action<NpgsqlDataSourceBuilder>? configureDataSourceBuilder = null) { // ... }}Parameters
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.namestringThe name of the component, which is used as the ServiceDescriptor.ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.configureSettingsAction<NpgsqlSettings>optionalAn optional method that can be used for customizing options. It's invoked after the settings are read from the configuration.configureDataSourceBuilderAction<NpgsqlDataSourceBuilder>optionalAn optional delegate that can be used for customizing the NpgsqlDataSourceBuilder.Exceptions
ArgumentNullExceptionThrown when builder or name is null.ArgumentExceptionThrown if mandatory name is empty.InvalidOperationExceptionThrown when mandatory NpgsqlSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:Npgsql:{name}" section.
AddNpgsqlDataSource(IHostApplicationBuilder, string, Action<NpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)Section titled AddNpgsqlDataSource(IHostApplicationBuilder, string, Action<NpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)extension Registers
NpgsqlDataSource service for connecting PostgreSQL database with Npgsql client. Configures health check, logging and telemetry for the Npgsql client. public static class AspirePostgreSqlNpgsqlExtensions{ public static void AddNpgsqlDataSource( this IHostApplicationBuilder builder, string connectionName, Action<NpgsqlSettings>? configureSettings = null, Action<NpgsqlDataSourceBuilder>? configureDataSourceBuilder = 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<NpgsqlSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.configureDataSourceBuilderAction<NpgsqlDataSourceBuilder>optionalAn optional delegate that can be used for customizing the NpgsqlDataSourceBuilder.Exceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory NpgsqlSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:Npgsql" section.