Skip to content
Docs Try Aspire

AspireAzureNpgsqlExtensions Methods

Class Methods 2 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)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to.
connectionName string A name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettings Action<AzureNpgsqlSettings> optional An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureDataSourceBuilder Action<NpgsqlDataSourceBuilder> optional An optional delegate that can be used for customizing the NpgsqlDataSourceBuilder.
ArgumentNullException Thrown if mandatory builder is null.
InvalidOperationException Thrown when mandatory NpgsqlSettings.ConnectionString is not provided or the AzureNpgsqlSettings.Credential is invalid.
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)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to.
name string The 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.
configureSettings Action<AzureNpgsqlSettings> optional An optional method that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureDataSourceBuilder Action<NpgsqlDataSourceBuilder> optional An optional delegate that can be used for customizing the NpgsqlDataSourceBuilder.
ArgumentNullException Thrown when builder or name is null.
ArgumentException Thrown if mandatory name is empty.
InvalidOperationException Thrown when mandatory NpgsqlSettings.ConnectionString is not provided or the AzureNpgsqlSettings.Credential is invalid.
Reads the configuration from "Aspire:Npgsql:{name}" section.