Table of Contents

Class ServiceCollectionExtensions

Namespace
Savvyio.Extensions.DependencyInjection.NATS
Assembly
Savvyio.Extensions.DependencyInjection.NATS.dll

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Examples

Register NATS command queues and event buses in the DI container with AddNatsCommandQueue and AddNatsEventBus. Both methods configure NATS JetStream settings and register the concrete queue/bus types.

using System;
using Microsoft.Extensions.DependencyInjection;
using Savvyio.Extensions.DependencyInjection;
using Savvyio.Extensions.DependencyInjection.NATS;

namespace ExampleApp;

public static class NatsRegistration
{
    public static IServiceCollection Configure(IServiceCollection services)
    {
        services.AddSavvyIO();
        services.AddNatsCommandQueue(options =>
        {
            options.NatsUrl = new Uri("nats://localhost:4222");
            options.Subject = "account-commands";
            options.StreamName = "savvyio-commands";
        });
        services.AddNatsEventBus(options =>
        {
            options.NatsUrl = new Uri("nats://localhost:4222");
            options.Subject = "account-events";
        });
        return services;
    }
}

Methods

AddNatsCommandQueue(IServiceCollection, Action<NatsCommandQueueOptions>, Action<ServiceOptions>)

Adds an NatsCommandQueue implementation to the specified IServiceCollection.

public static IServiceCollection AddNatsCommandQueue(this IServiceCollection services, Action<NatsCommandQueueOptions> natsSetup, Action<ServiceOptions> serviceSetup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

natsSetup Action<NatsCommandQueueOptions>

The NatsCommandQueueOptions that needs to be configured.

serviceSetup Action<ServiceOptions>

The ServiceOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional calls can be chained.

Remarks

The implementation will be type forwarded accordingly.

Exceptions

ArgumentNullException

services cannot be null.

AddNatsCommandQueue<TMarker>(IServiceCollection, Action<NatsCommandQueueOptions<TMarker>>, Action<ServiceOptions>)

Adds an NatsCommandQueue<TMarker> implementation to the specified IServiceCollection.

public static IServiceCollection AddNatsCommandQueue<TMarker>(this IServiceCollection services, Action<NatsCommandQueueOptions<TMarker>> natsSetup, Action<ServiceOptions> serviceSetup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

natsSetup Action<NatsCommandQueueOptions<TMarker>>

The NatsCommandQueueOptions<TMarker> that needs to be configured.

serviceSetup Action<ServiceOptions>

The ServiceOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional calls can be chained.

Type Parameters

TMarker

Remarks

The implementation will be type forwarded accordingly.

Exceptions

ArgumentNullException

services cannot be null.

AddNatsEventBus(IServiceCollection, Action<NatsEventBusOptions>, Action<ServiceOptions>)

Adds an NatsEventBus implementation to the specified IServiceCollection.

public static IServiceCollection AddNatsEventBus(this IServiceCollection services, Action<NatsEventBusOptions> natsSetup, Action<ServiceOptions> serviceSetup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

natsSetup Action<NatsEventBusOptions>

The NatsEventBusOptions that needs to be configured.

serviceSetup Action<ServiceOptions>

The ServiceOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional calls can be chained.

Remarks

The implementation will be type forwarded accordingly.

Exceptions

ArgumentNullException

services cannot be null.

AddNatsEventBus<TMarker>(IServiceCollection, Action<NatsEventBusOptions<TMarker>>, Action<ServiceOptions>)

Adds an NatsEventBus<TMarker> implementation to the specified IServiceCollection.

public static IServiceCollection AddNatsEventBus<TMarker>(this IServiceCollection services, Action<NatsEventBusOptions<TMarker>> natsSetup, Action<ServiceOptions> serviceSetup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

natsSetup Action<NatsEventBusOptions<TMarker>>

The NatsEventBusOptions<TMarker> that needs to be configured.

serviceSetup Action<ServiceOptions>

The ServiceOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional calls can be chained.

Type Parameters

TMarker

Remarks

The implementation will be type forwarded accordingly.

Exceptions

ArgumentNullException

services cannot be null.