public static IServiceCollection AddIntegrations(this IServiceCollection services)
        {
            services.AddTransient <IClienteIntegrationEventService, ClienteIntegrationEventService>();

            services.AddSingleton <IRabbitMQPersistentConnection>(sp =>
            {
                var logger = sp.GetRequiredService <ILogger <RabbitMQPersistentConnection> >();

                var rabbitMQConfiguration = sp.GetRequiredService <IOptions <RabbitMQConfiguration> >().Value;

                var connectionFactoryConfig = new RabbitMQConnectionFactoryConfiguration(
                    rabbitMQConfiguration.EventBusConnection,
                    rabbitMQConfiguration.EventBusUserName,
                    rabbitMQConfiguration.EventBusPassword);

                return(new RabbitMQPersistentConnection(connectionFactoryConfig, logger));
            });

            return(services);
        }
Ejemplo n.º 2
0
        public static IServiceCollection AddEventBus(this IServiceCollection services)
        {
            services.AddSingleton <IEventBus, EventBusRabbitMQ>(sp =>
            {
                var rabbitMQPersistentConnection = sp.GetRequiredService <IRabbitMQPersistentConnection>();
                var logger = sp.GetRequiredService <ILogger <EventBusRabbitMQ> >();
                var eventBusSubcriptionsManager = sp.GetRequiredService <IEventBusSubscriptionsManager>();
                var serviceScopeFactory         = sp.GetRequiredService <IServiceScopeFactory>();
                var iLifetimeScope = sp.GetRequiredService <ILifetimeScope>();

                var rabbitMQConfiguration = sp.GetRequiredService <IOptions <RabbitMQConfiguration> >().Value;

                var connectionFactoryConfig = new RabbitMQConnectionFactoryConfiguration(
                    rabbitMQConfiguration.EventBusConnection,
                    rabbitMQConfiguration.EventBusUserName,
                    rabbitMQConfiguration.EventBusPassword);

                var retryCount = 5;
                if (!string.IsNullOrEmpty(rabbitMQConfiguration.EventBusRetryCount))
                {
                    retryCount = int.Parse(rabbitMQConfiguration.EventBusRetryCount);
                }

                return(new EventBusRabbitMQ(
                           rabbitMQPersistentConnection,
                           logger,
                           eventBusSubcriptionsManager,
                           serviceScopeFactory,
                           iLifetimeScope,
                           rabbitMQConfiguration.SubscriptionClientName,
                           retryCount));
            });

            services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();

            return(services);
        }