Freigeben über


AspirePostgreSqlNpgsqlExtensions.AddKeyedNpgsqlDataSource Method

Definition

Registers Npgsql.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 void AddKeyedNpgsqlDataSource (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string name, Action<Aspire.Npgsql.NpgsqlSettings>? configureSettings = default, Action<Npgsql.NpgsqlDataSourceBuilder>? configureDataSourceBuilder = default);
static member AddKeyedNpgsqlDataSource : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Npgsql.NpgsqlSettings> * Action<Npgsql.NpgsqlDataSourceBuilder> -> unit
<Extension()>
Public Sub AddKeyedNpgsqlDataSource (builder As IHostApplicationBuilder, name 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.

name
String

The name of the component, which is used as the ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.

configureSettings
Action<NpgsqlSettings>

An optional method 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 when builder or name is null.

Thrown if mandatory name is empty.

Thrown when mandatory ConnectionString is not provided.

Remarks

Reads the configuration from "Aspire:Npgsql:{name}" section.

Applies to