Table of Contents

ServiceCollectionExtensions Class

Definition

Namespace
Savvyio.Extensions.DependencyInjection.NATS
Assemblies
Savvyio.Extensions.DependencyInjection.NATS.dll
Source
src/Savvyio.Extensions.DependencyInjection.NATS/ServiceCollectionExtensions.cs

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
object
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

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

Adds an NatsCommandQueue implementation to the specified IServiceCollection.

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

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

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

Adds an NatsEventBus implementation to the specified IServiceCollection.

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

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