Esempio n. 1
0
        public static IAlohaBuilder AddMongo(this IAlohaBuilder builder, Func <IMongoDbOptionsBuilder,
                                                                               IMongoDbOptionsBuilder> buildOptions, Type seederType = null, bool registerConventions = true)
        {
            var mongoOptions = buildOptions(new MongoDbOptionsBuilder()).Build();

            return(builder.AddMongo(mongoOptions, seederType, registerConventions));
        }
Esempio n. 2
0
        public static TModel GetOptions <TModel>(this IAlohaBuilder builder, string settingsSectionName)
            where TModel : new()
        {
            using var serviceProvider = builder.Services.BuildServiceProvider();
            var configuration = serviceProvider.GetService <IConfiguration>();

            return(configuration.GetOptions <TModel>(settingsSectionName));
        }
Esempio n. 3
0
        public static IAlohaBuilder AddQueryHandlers(this IAlohaBuilder builder)
        {
            builder.Services.Scan(s =>
                                  s.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies())
                                  .AddClasses(c => c.AssignableTo(typeof(IQueryHandler <,>)))
                                  .AsImplementedInterfaces()
                                  .WithTransientLifetime());

            return(builder);
        }
Esempio n. 4
0
        public static IAlohaBuilder AddMongoRepository <TEntity, TIdentifiable>(this IAlohaBuilder builder,
                                                                                string collectionName)
            where TEntity : IIdentifiable <TIdentifiable>
        {
            builder.Services.AddTransient <IMongoRepository <TEntity, TIdentifiable> >(sp =>
            {
                var database = sp.GetService <IMongoDatabase>();
                return(new MongoRepository <TEntity, TIdentifiable>(database, collectionName));
            });

            return(builder);
        }
Esempio n. 5
0
        public static IAlohaBuilder AddAmazonKinesis(this IAlohaBuilder builder, string sectionName = SectionName)
        {
            var options = builder.GetOptions <AmazonKinesisOptions>(sectionName);

            builder.Services.AddSingleton(options);

            builder.Services.AddSingleton <IAmazonKinesisClient, AmazonKinesisClient>();

            builder.Services.AddSingleton <IStreamPublisher, AmazonKinesisPublisher>();

            return(builder);
        }
Esempio n. 6
0
        public static IAlohaBuilder AddMongo(this IAlohaBuilder builder, string sectionName = SectionName,
                                             Type seederType = null, bool registerConventions = true)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

            var mongoOptions = builder.GetOptions <MongoDbOptions>(sectionName);

            return(builder.AddMongo(mongoOptions, seederType, registerConventions));
        }
Esempio n. 7
0
        public static IAlohaBuilder UseSerilog(this IAlohaBuilder builder, IConfiguration configuration)
        {
            Serilog.ILogger logger = new LoggerConfiguration()
                                     .ReadFrom.Configuration(configuration)
                                     .CreateLogger();

            builder.Services.AddSingleton(logger);

            var logEvent = new LogEvent(Guid.NewGuid(), Guid.NewGuid());

            builder.Services.Add(new ServiceDescriptor(typeof(ILogger), new SerilogLogger(logger, logEvent)));

            return(builder);
        }
Esempio n. 8
0
        public static IAlohaBuilder AddAmazonSQS(this IAlohaBuilder builder, string sectionName = SectionName)
        {
            builder.Services.AddSingleton <ICorrelationContextAccessor, CorrelationContextAccessor>();
            builder.Services.AddTransient <IAmazonSQSClient, AmazonSQSClient>();
            builder.Services.AddScoped <IConventions, MessageConventions>();
            builder.Services.AddScoped <IConventionsProvider, ConventionsProvider>();
            builder.Services.AddScoped <IBusPublisher, AmazonSQSPublisher>();
            builder.Services.AddScoped <IBusConsumer, AmazonSQSConsumer>();
            builder.Services.AddSingleton <IAlohaSerializer, NewtonsoftJsonAlohaSerializer>();

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

            builder.Services.AddSingleton(options);

            return(builder);
        }
Esempio n. 9
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. 10
0
        public static IAlohaBuilder AddAmazonS3(this IAlohaBuilder builder, string sectionName = SectionName)
        {
            var options = builder.GetOptions <AmazonS3Options>(sectionName);

            builder.Services.AddSingleton(options);

            IAmazonS3 amazonS3 = new Amazon.S3.AmazonS3Client(
                new BasicAWSCredentials(options.AccessKey, options.SecretKey),
                new AmazonS3Config {
                ServiceURL = options.ServiceUrl
            });

            builder.Services.AddSingleton(amazonS3);

            builder.Services.AddSingleton <IStorageClient, AmazonS3Client>();

            return(builder);
        }
Esempio n. 11
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. 12
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);
        }
Esempio n. 13
0
 public static IAlohaBuilder AddInMemoryNotificationDispatcher(this IAlohaBuilder builder)
 {
     builder.Services.AddScoped <INotificationDispatcher, NotificationDispatcher>();
     return(builder);
 }
Esempio n. 14
0
 public static IAlohaBuilder AddInMemoryEventDispatcher(this IAlohaBuilder builder)
 {
     builder.Services.AddSingleton <IEventDispatcher, EventDispatcher>();
     return(builder);
 }
Esempio n. 15
0
 public static IAlohaBuilder AddServiceBusEventDispatcher(this IAlohaBuilder builder)
 {
     builder.Services.AddScoped <IEventDispatcher, ServiceBusMessageDispatcher>();
     return(builder);
 }
Esempio n. 16
0
 public static IAlohaBuilder AddInMemoryQueryDispatcher(this IAlohaBuilder builder)
 {
     builder.Services.AddScoped <IQueryDispatcher, QueryDispatcher>();
     return(builder);
 }
Esempio n. 17
0
 public static IAlohaBuilder AddInMemoryCommandDispatcher(this IAlohaBuilder builder)
 {
     builder.Services.AddScoped <ICommandDispatcher, CommandDispatcher>();
     return(builder);
 }