AspireAzureNpgsqlExtensions Methods
ClassMethods2 members
Extension methods for connecting to an Azure Database for PostgreSQL with Npgsql client
AddAzureNpgsqlDataSource(IHostApplicationBuilder, string, Action<AzureNpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)Section titled AddAzureNpgsqlDataSource(IHostApplicationBuilder, string, Action<AzureNpgsqlSettings>, 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 AspireAzureNpgsqlExtensions{ public static void AddAzureNpgsqlDataSource( this IHostApplicationBuilder builder, string connectionName, Action<AzureNpgsqlSettings>? 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<AzureNpgsqlSettings>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 or the AzureNpgsqlSettings.Credential is invalid.Remarks
Reads the configuration from "Aspire:Npgsql" section.
AddKeyedAzureNpgsqlDataSource(IHostApplicationBuilder, string, Action<AzureNpgsqlSettings>, Action<NpgsqlDataSourceBuilder>)Section titled AddKeyedAzureNpgsqlDataSource(IHostApplicationBuilder, string, Action<AzureNpgsqlSettings>, 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 AspireAzureNpgsqlExtensions{ public static void AddKeyedAzureNpgsqlDataSource( this IHostApplicationBuilder builder, string name, Action<AzureNpgsqlSettings>? 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<AzureNpgsqlSettings>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 or the AzureNpgsqlSettings.Credential is invalid.Remarks
Reads the configuration from "Aspire:Npgsql:{name}" section.