Freigeben über


AspireNatsClientExtensions.AddNatsClient Method

Definition

Registers NATS.Client.Core.INatsConnection service for connecting NATS server with NATS client. Configures health check and logging for the NATS client.

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

connectionName
String

A name used 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 if mandatory builder is null.

Thrown when mandatory ConnectionString is not provided.

Applies to