[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,24 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using RabbitMQ.Client;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
|
||||
public static class RabbitMQExtensions
|
||||
{
|
||||
public static EventBusBuilder<RabbitMQEventBus> AddRabbitMQ(this IServiceCollection services, Action<RabbitMQOptions> configure)
|
||||
{
|
||||
services.Configure(configure);
|
||||
services.AddSingleton<IConnectionFactory, ConnectionFactory>(provider =>
|
||||
{
|
||||
var options = provider.GetService<IOptions<RabbitMQOptions>>();
|
||||
ConnectionFactory factory = new ConnectionFactory();
|
||||
factory.Uri = new Uri(options.Value.ConnectionString);
|
||||
return factory;
|
||||
});
|
||||
services.AddSingleton<RabbitMQConnectionProvider>();
|
||||
services.AddHostedService<RabbitMQEventBus>();
|
||||
return services.AddEventBus<RabbitMQEventBus>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user