Пример #1
0
        public static void SetupRabbitMqEventBus(this ContainerBuilder builder, IConfiguration config)
        {
            builder.RegisterType <GenericEventBusSubscriptionManager>()
            .As <IEventBusSubscriptionManager>()
            .SingleInstance();

            builder.Register <RabbitMqEventBus>(ctx =>
            {
                var conn        = ctx.Resolve <IRabbitMqConnection>();
                var logger      = ctx.Resolve <ILogger <RabbitMqEventBus> >();
                var scope       = ctx.Resolve <ILifetimeScope>();
                var subsManager = ctx.Resolve <IEventBusSubscriptionManager>();

                var rabbitConfig = new RabbitConfig
                {
                    ExchangeName      = config["rabbitMq:exchangeName"],
                    MyQueueName       = config["rabbitMq:myQueueName"],
                    MessageTimeToLive = config["rabbitMq:messageTTL"],
                };

                return(new RabbitMqEventBus(conn, logger, scope, subsManager, rabbitConfig));
            })
            .As <IEventBus>()
            .SingleInstance();
        }
Пример #2
0
        public static IServiceCollection AddRabbitMqEventBus(this IServiceCollection services, IConfiguration config)
        {
            services.AddSingleton <IEventBusSubscriptionManager, GenericEventBusSubscriptionManager>();
            services.AddSingleton <IEventBus, RabbitMqEventBus>(provider =>
            {
                var conn        = provider.GetRequiredService <IRabbitMqConnection>();
                var logger      = provider.GetRequiredService <ILogger <RabbitMqEventBus> >();
                var scope       = provider.GetRequiredService <ILifetimeScope>();
                var subsManager = provider.GetRequiredService <IEventBusSubscriptionManager>();

                var rabbitConfig = new RabbitConfig
                {
                    ExchangeName      = config["RabbitMq:exchangeName"],
                    MyQueueName       = config["RabbitMq:myQueueName"],
                    MessageTimeToLive = config["RabbitMq:messageTTL"]
                };

                return(new RabbitMqEventBus(conn, logger, scope, subsManager, rabbitConfig));
            });

            return(services);
        }