public static IDrexBuilder AddMongo(this IDrexBuilder builder, MongoDbOptions mongoOptions) { 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)); }); builder.Services.AddTransient <IMongoDbInitializer, MongoDbInitializer>(); builder.Services.AddTransient <IMongoSessionFactory, MongoSessionFactory>(); builder.AddInitializer <IMongoDbInitializer>(); return(builder); }
public static IDrexBuilder AddRabbitMq(this IDrexBuilder builder, string sectionName = SectionName, Func <IRabbitMqPluginsRegistry, IRabbitMqPluginsRegistry> plugins = null) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var options = builder.GetOptions <RabbitMqOptions>(sectionName); builder.Services.AddSingleton(options); if (!builder.TryRegister(RegistryName)) { return(builder); } if (options.HostNames is null || !options.HostNames.Any()) { throw new ArgumentException("RabbitMQ hostnames are not specified.", nameof(options.HostNames)); } 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.AddTransient <RabbitMqExchangeInitializer>(); builder.Services.AddHostedService <RabbitMqHostedService>(); builder.AddInitializer <RabbitMqExchangeInitializer>(); var pluginsRegistry = new RabbitMqPluginsRegistry(); builder.Services.AddSingleton <IRabbitMqPluginsRegistryAccessor>(pluginsRegistry); builder.Services.AddSingleton <IRabbitMqPluginsExecutor, RabbitMqPluginsExecutor>(); plugins?.Invoke(pluginsRegistry); var connection = new ConnectionFactory { Port = options.Port, VirtualHost = options.VirtualHost, UserName = options.Username, Password = options.Password, RequestedConnectionTimeout = options.RequestedConnectionTimeout, SocketReadTimeout = options.SocketReadTimeout, SocketWriteTimeout = options.SocketWriteTimeout, RequestedChannelMax = options.RequestedChannelMax, RequestedFrameMax = options.RequestedFrameMax, RequestedHeartbeat = options.RequestedHeartbeat, UseBackgroundThreadsForIO = options.UseBackgroundThreadsForIO, DispatchConsumersAsync = true, Ssl = options.Ssl is null ? new SslOption() : new SslOption(options.Ssl.ServerName, options.Ssl.CertificatePath, options.Ssl.Enabled) }.CreateConnection(options.HostNames.ToList(), options.ConnectionName);
public static IDrexBuilder AddSqlServer <TMyDbContext>(this IDrexBuilder builder, SqlServerOptions sqlServerOptions) where TMyDbContext : DbContext { if (!builder.TryRegister(RegistryName)) { return(builder); } builder.Services.AddSingleton(sqlServerOptions); builder.Services.AddTransient <ISqlServerInitializer, SqlServerInitializer>(); builder.AddInitializer <ISqlServerInitializer>(); builder.Services.AddEntityFrameworkMsSql <TMyDbContext>(sqlServerOptions); return(builder); }