Partager via


AspireNatsClientExtensions.AddKeyedNatsClient Method

Definition

Registers NATS.Client.Core.INatsConnection as a keyed service for given name for connecting NATS server with NATS client. Configures health check and logging for the NATS client.

public static void AddKeyedNatsClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string name, Action<Aspire.NATS.Net.NatsClientSettings>? configureSettings = default, Func<NATS.Client.Core.NatsOpts,NATS.Client.Core.NatsOpts>? configureOptions = default);
static member AddKeyedNatsClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.NATS.Net.NatsClientSettings> * Func<NATS.Client.Core.NatsOpts, NATS.Client.Core.NatsOpts> -> unit
<Extension()>
Public Sub AddKeyedNatsClient (builder As IHostApplicationBuilder, name As String, Optional configureSettings As Action(Of NatsClientSettings) = Nothing, Optional configureOptions As Func(Of NatsOpts, NatsOpts) = 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<NatsClientSettings>

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

configureOptions
Func<NATS.Client.Core.NatsOpts,NATS.Client.Core.NatsOpts>

An optional delegate that can be used for customizing NATS options that aren't exposed as standard configuration.

Exceptions

Thrown when builder or name is null.

Thrown if mandatory name is empty.

Thrown when mandatory ConnectionString is not provided.

Applies to