public static IServiceCollection AddEventBus(this IServiceCollection service, IConfiguration configuration) { var settings = new RabbitMqConnectionSettings(); configuration.GetSection(ConfigSectionName).Bind(settings); service.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); service.AddSingleton <IEventBus, RabbitMQEventBus>(sp => new RabbitMQEventBus(sp, settings.SubscriberId, settings.Retry, settings.BrokerName)); return(service); }
public static IServiceCollection AddBrokerServiceConnection(this IServiceCollection service, IConfiguration configuration) { var settings = new RabbitMqConnectionSettings(); configuration.GetSection(ConfigSectionName).Bind(settings); service.AddSingleton <IAmqpConnection>(sp => { var logger = sp.GetRequiredService <ILogger <RabbitMQConnection> >(); var connectionFactory = new ConnectionFactory { HostName = settings.HostName, Port = settings.Port, UserName = settings.UserName, Password = settings.Password, }; return(new RabbitMQConnection(connectionFactory, logger, settings.Retry)); }); return(service); }