NatsEventBus<TMarker> Class
Definition
- Namespace
- Savvyio.Extensions.DependencyInjection.NATS.EventDriven
- Assemblies
- Savvyio.Extensions.DependencyInjection.NATS.dll
Provides a default implementation of the NatsMessage class for messages holding an IIntegrationEvent implementation.
public class NatsEventBus<TMarker> : NatsEventBus, IDisposable, IAsyncDisposable, IHealthCheckProvider<INatsConnection>, IPublishSubscribeChannel<IIntegrationEvent, TMarker>, IPublishSubscribeChannel<IIntegrationEvent>, IPublisher<IIntegrationEvent, TMarker>, IPublisher<IIntegrationEvent>, ISubscriber<IIntegrationEvent, TMarker>, ISubscriber<IIntegrationEvent>, IDependencyInjectionMarker<TMarker>
Type Parameters
TMarker
- Inheritance
-
objectNatsEventBus<TMarker>
- Implements
-
IHealthCheckProvider<INatsConnection>IPublishSubscribeChannel<IIntegrationEvent, TMarker>IPublisher<IIntegrationEvent, TMarker>ISubscriber<IIntegrationEvent, TMarker>IDependencyInjectionMarker<TMarker>
- Inherited Members
Examples
NatsEventBus<TMarker> is the DI-registered NATS event bus with a lifetime marker. Register it with AddNatsEventBus and resolve it as NatsEventBus or IPublishSubscribeChannel<IIntegrationEvent>.
using System;
using Microsoft.Extensions.DependencyInjection;
using Savvyio.EventDriven;
using Savvyio.Extensions.DependencyInjection;
using Savvyio.Extensions.DependencyInjection.NATS;
using Savvyio.Extensions.NATS.EventDriven;
using Savvyio.Messaging;
namespace ExampleApp;
public static class NatsBusUsage
{
public static NatsEventBus GetBus(IServiceProvider provider)
{
return provider.GetRequiredService<NatsEventBus>();
}
public static IPublishSubscribeChannel<IIntegrationEvent> GetChannel(IServiceProvider provider)
{
return provider.GetRequiredService<IPublishSubscribeChannel<IIntegrationEvent>>();
}
public static IServiceCollection Register(IServiceCollection services)
{
services.AddSavvyIO();
services.AddNatsEventBus(o => { o.NatsUrl = new Uri("nats://localhost:4222"); o.Subject = "events"; });
return services;
}
}
Constructors
| Name | Description |
|---|---|
| NatsEventBus(IMarshaller, NatsEventBusOptions<TMarker>) | Initializes a new instance of the NatsEventBus class. |
See Also
IPublishSubscribeChannel<TRequest, TMarker>