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)); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
public static IAlohaBuilder AddInMemoryNotificationDispatcher(this IAlohaBuilder builder) { builder.Services.AddScoped <INotificationDispatcher, NotificationDispatcher>(); return(builder); }
public static IAlohaBuilder AddInMemoryEventDispatcher(this IAlohaBuilder builder) { builder.Services.AddSingleton <IEventDispatcher, EventDispatcher>(); return(builder); }
public static IAlohaBuilder AddServiceBusEventDispatcher(this IAlohaBuilder builder) { builder.Services.AddScoped <IEventDispatcher, ServiceBusMessageDispatcher>(); return(builder); }
public static IAlohaBuilder AddInMemoryQueryDispatcher(this IAlohaBuilder builder) { builder.Services.AddScoped <IQueryDispatcher, QueryDispatcher>(); return(builder); }
public static IAlohaBuilder AddInMemoryCommandDispatcher(this IAlohaBuilder builder) { builder.Services.AddScoped <ICommandDispatcher, CommandDispatcher>(); return(builder); }