Esempio n. 1
0
        public static IAlohaBuilder AddRabbitMq(this IAlohaBuilder builder, string sectionName           = SectionName,
                                                Action <ConnectionFactory> connectionFactoryConfigurator = null)
        {
            builder.Services.AddSingleton <IContextProvider, ContextProvider>();
            //builder.Services.AddSingleton<ICorrelationContextAccessor>(new CorrelationContextAccessor());
            //builder.Services.AddSingleton<IMessagePropertiesAccessor>(new MessagePropertiesAccessor());
            builder.Services.AddSingleton <IConventionsBuilder, ConventionsBuilder>();
            builder.Services.AddSingleton <IConventionsProvider, ConventionsProvider>();
            builder.Services.AddSingleton <IConventionsRegistry, ConventionsRegistry>();
            builder.Services.AddSingleton <IRabbitMqSerializer, NewtonsoftJsonRabbitMqSerializer>();
            builder.Services.AddSingleton <IRabbitMqClient, RabbitMqClient>();
            builder.Services.AddSingleton <IBusPublisher, RabbitMqPublisher>();
            builder.Services.AddSingleton <IBusSubscriber, RabbitMqSubscriber>();
            builder.Services.AddSingleton <IRabbitMqPluginsExecutor, RabbitMqPluginsExecutor>();
            builder.Services.AddTransient <RabbitMqExchangeInitializer>();
            builder.Services.AddHostedService <RabbitMqHostedService>();
            builder.AddInitializer <RabbitMqExchangeInitializer>();

            var options = builder.GetOptions <RabbitMqOptions>(sectionName);

            builder.Services.AddSingleton(options);
            var connectionFactory = new ConnectionFactory
            {
                Port        = options.Port,
                VirtualHost = options.VirtualHost,
                UserName    = options.Username,
                Password    = options.Password,
                //RequestedHeartbeat = options.RequestedHeartbeat,
                //RequestedConnectionTimeout = options.RequestedConnectionTimeout,
                //SocketReadTimeout = options.SocketReadTimeout,
                //SocketWriteTimeout = options.SocketWriteTimeout,
                //RequestedChannelMax = options.RequestedChannelMax,
                //RequestedFrameMax = options.RequestedFrameMax,
                //UseBackgroundThreadsForIO = options.UseBackgroundThreadsForIO,
                DispatchConsumersAsync = true,
                //ContinuationTimeout = options.ContinuationTimeout,
                //HandshakeContinuationTimeout = options.HandshakeContinuationTimeout,
                //NetworkRecoveryInterval = options.NetworkRecoveryInterval,
            };

            connectionFactoryConfigurator?.Invoke(connectionFactory);
            var connection = connectionFactory.CreateConnection(options.HostNames, options.ConnectionName);

            builder.Services.AddSingleton(connection);

            return(builder);
        }
Esempio n. 2
0
        public static IAlohaBuilder AddMongo(this IAlohaBuilder builder, MongoDbOptions mongoOptions,
                                             Type seederType = null, bool registerConventions = true)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            builder.Services.AddSingleton(mongoOptions);
            builder.Services.AddSingleton <IMongoClient>(sp =>
            {
                var options = sp.GetService <MongoDbOptions>();
                return(new MongoClient(options.ConnectionString));
            });
            builder.Services.AddTransient(sp =>
            {
                var options = sp.GetService <MongoDbOptions>();
                var client  = sp.GetService <IMongoClient>();
                return(client.GetDatabase(options.Database, new MongoDatabaseSettings {
                    GuidRepresentation = GuidRepresentation.Standard
                }));
            });

            builder.Services.AddTransient <IMongoDbInitializer, MongoDbInitializer>();
            builder.Services.AddTransient <IMongoSessionFactory, MongoSessionFactory>();

            if (seederType is null)
            {
                builder.Services.AddTransient <IMongoDbSeeder, MongoDbSeeder>();
            }
            else
            {
                builder.Services.AddTransient(typeof(IMongoDbSeeder), seederType);
            }

            builder.AddInitializer <IMongoDbInitializer>();
            if (registerConventions && !_conventionsRegistered)
            {
                RegisterConventions();
            }

            return(builder);
        }
Esempio n. 3
0
        public static IAlohaBuilder AddRabbitMq(this IAlohaBuilder builder, string sectionName           = SectionName,
                                                Action <ConnectionFactory> connectionFactoryConfigurator = null)
        {
            builder.Services.AddSingleton <IContextProvider, ContextProvider>();

            builder.Services.AddSingleton <ICorrelationContextAccessor, CorrelationContextAccessor>();
            //builder.Services.AddSingleton<IMessagePropertiesAccessor>(new MessagePropertiesAccessor());
            builder.Services.AddSingleton <IConventionsBuilder, ConventionsBuilder>();
            builder.Services.AddSingleton <IConventionsProvider, ConventionsProvider>();
            builder.Services.AddSingleton <IConventionsRegistry, ConventionsRegistry>();
            builder.Services.AddSingleton <IRabbitMqSerializer, NewtonsoftJsonRabbitMqSerializer>();
            builder.Services.AddSingleton <IRabbitMqClient, RabbitMqClient>();
            builder.Services.AddSingleton <IBusPublisher, RabbitMqPublisher>();
            builder.Services.AddSingleton <IBusSubscriber, RabbitMqSubscriber>();
            builder.Services.AddSingleton <IRabbitMqPluginsExecutor, RabbitMqPluginsExecutor>();
            builder.Services.AddSingleton <RabbitMqExchangeInitializer>();
            builder.Services.AddSingleton <RabbitMqHostedService>();

            builder.AddInitializer <RabbitMqExchangeInitializer>();

            var options = builder.GetOptions <RabbitMqOptions>(sectionName);

            builder.Services.AddSingleton(options);

            var connectionFactory = new ConnectionFactory
            {
                Port                   = options.Port,
                VirtualHost            = options.VirtualHost,
                UserName               = options.Username,
                Password               = options.Password,
                DispatchConsumersAsync = true
            };

            connectionFactoryConfigurator?.Invoke(connectionFactory);
            var connection = connectionFactory.CreateConnection(options.HostNames, options.ConnectionName);

            builder.Services.AddSingleton(connection);

            return(builder);
        }