[FA-4] Adds an event bus infrastructure, a RabbitMQ implementation and rewires existing mutations on NovelService to utilize it.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
public class EventBusBuilder<TEventBus> where TEventBus : class, IEventBus
|
||||
{
|
||||
private readonly IServiceCollection _services;
|
||||
private readonly SubscriptionManager _subscriptionManager;
|
||||
|
||||
public EventBusBuilder(IServiceCollection services)
|
||||
{
|
||||
_services = services;
|
||||
_services.AddSingleton<IEventBus, TEventBus>();
|
||||
|
||||
_subscriptionManager = new SubscriptionManager();
|
||||
_services.AddSingleton<SubscriptionManager>(_subscriptionManager);
|
||||
}
|
||||
|
||||
public EventBusBuilder<TEventBus> Subscribe<TEvent, TEventHandler>() where TEvent : IntegrationEvent where TEventHandler : class, IIntegrationEventHandler<TEvent>
|
||||
{
|
||||
_services.AddKeyedTransient<IIntegrationEventHandler, TEventHandler>(typeof(TEvent).Name);
|
||||
_subscriptionManager.RegisterSubscription<TEvent>();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user