Share via


AspirePostgreSqlNpgsqlExtensions.AddNpgsqlDataSource Method

Definition

Registers Npgsql.NpgsqlDataSource service for connecting PostgreSQL database with Npgsql client. Configures health check, logging and telemetry for the Npgsql client.

public static void AddNpgsqlDataSource (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.Npgsql.NpgsqlSettings>? configureSettings = default, Action<Npgsql.NpgsqlDataSourceBuilder>? configureDataSourceBuilder = default);
static member AddNpgsqlDataSource : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Npgsql.NpgsqlSettings> * Action<Npgsql.NpgsqlDataSourceBuilder> -> unit
<Extension()>
Public Sub AddNpgsqlDataSource (builder As IHostApplicationBuilder, connectionName As String, Optional configureSettings As Action(Of NpgsqlSettings) = Nothing, Optional configureDataSourceBuilder As Action(Of NpgsqlDataSourceBuilder) = Nothing)

Parameters

builder
IHostApplicationBuilder

The 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<NpgsqlSettings>

An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

configureDataSourceBuilder
Action<Npgsql.NpgsqlDataSourceBuilder>

An optional delegate that can be used for customizing the Npgsql.NpgsqlDataSourceBuilder.

Exceptions

Thrown if mandatory builder is null.

Thrown when mandatory ConnectionString is not provided.

Remarks

Reads the configuration from "Aspire:Npgsql" section.

Applies to