private static IDrexBuilder AddWebApiSwaggerDocs(this IDrexBuilder builder, Action <IDrexBuilder> registerSwagger) { registerSwagger(builder); builder.Services.AddSwaggerGen(c => c.DocumentFilter <WebApiDocumentFilter>()); return(builder); }
public static IDrexBuilder AddRedis(this IDrexBuilder builder, Func <IRedisOptionsBuilder, IRedisOptionsBuilder> buildOptions) { var options = buildOptions(new RedisOptionsBuilder()).Build(); return(builder.AddRedis(options)); }
public static IDrexBuilder AddMongo(this IDrexBuilder builder, Func <IMongoDbOptionsBuilder, IMongoDbOptionsBuilder> buildOptions) { var mongoOptions = buildOptions(new MongoDbOptionsBuilder()).Build(); return(builder.AddMongo(mongoOptions)); }
public static IDrexBuilder AddConsul(this IDrexBuilder builder, ConsulOptions options, HttpClientOptions httpClientOptions) { builder.Services.AddSingleton(options); if (!options.Enabled || !builder.TryRegister(RegistryName)) { return(builder); } if (httpClientOptions.Type?.ToLowerInvariant() == "consul") { builder.Services.AddTransient <ConsulServiceDiscoveryMessageHandler>(); builder.Services.AddHttpClient <IConsulHttpClient, ConsulHttpClient>("consul-http") .AddHttpMessageHandler <ConsulServiceDiscoveryMessageHandler>(); builder.RemoveHttpClient(); builder.Services.AddHttpClient <IHttpClient, ConsulHttpClient>("consul") .AddHttpMessageHandler <ConsulServiceDiscoveryMessageHandler>(); } builder.Services.AddTransient <IConsulServicesRegistry, ConsulServicesRegistry>(); var registration = builder.CreateConsulAgentRegistration(options); if (registration is null) { return(builder); } builder.Services.AddSingleton(registration); return(builder); }
public static void AddConsulHttpClient(this IDrexBuilder builder, string clientName, string serviceName) { builder.Services.AddHttpClient <IHttpClient, ConsulHttpClient>(clientName) .AddHttpMessageHandler(c => new ConsulServiceDiscoveryMessageHandler( c.GetService <IConsulServicesRegistry>(), c.GetService <ConsulOptions>(), serviceName, true)); }
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 AddConsul(this IDrexBuilder builder, Func <IConsulOptionsBuilder, IConsulOptionsBuilder> buildOptions, HttpClientOptions httpClientOptions) { var options = buildOptions(new ConsulOptionsBuilder()).Build(); return(builder.AddConsul(options, httpClientOptions)); }
public static IDrexBuilder AddSwaggerDocs(this IDrexBuilder builder, Func <ISwaggerOptionsBuilder, ISwaggerOptionsBuilder> buildOptions) { var options = buildOptions(new SwaggerOptionsBuilder()).Build(); return(builder.AddSwaggerDocs(options)); }
private static IDrexBuilder AddServiceClient <T>(this IDrexBuilder builder, string serviceName, RestEaseOptions options, Action <IDrexBuilder> registerFabio) where T : class { if (!builder.TryRegister(RegistryName)) { return(builder); } var clientName = typeof(T).ToString(); switch (options.LoadBalancer?.ToLowerInvariant()) { case "consul": builder.AddConsulHttpClient(clientName, serviceName); break; case "fabio": builder.AddFabioHttpClient(clientName, serviceName); break; default: ConfigureDefaultClient(builder.Services, clientName, serviceName, options); break; } ConfigureForwarder <T>(builder.Services, clientName); registerFabio(builder); return(builder); }
public static IDrexBuilder AddSwaggerDocs(this IDrexBuilder builder, SwaggerOptions options) { if (!options.Enabled || !builder.TryRegister(RegistryName)) { return(builder); } builder.Services.AddSingleton(options); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc(options.Name, new OpenApiInfo { Title = options.Title, Version = options.Version }); if (options.IncludeSecurity) { c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); } }); return(builder); }
public static IDrexBuilder AddRabbitMq <TContext>(this IDrexBuilder builder, RabbitMqOptions options, Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins = null, RedisOptions redisOptions = null) where TContext : class, new() { return(builder.AddRabbitMq <TContext>(options, plugins, b => b.AddRedis(redisOptions ?? new RedisOptions()))); }
public static IDrexBuilder AddExceptionToMessageMapper <T>(this IDrexBuilder builder) where T : class, IExceptionToMessageMapper { builder.Services.AddTransient <IExceptionToMessageMapper, T>(); 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 AddErrorHandler <T>(this IDrexBuilder builder) where T : class, IExceptionToResponseMapper { builder.Services.AddTransient <ErrorHandlerMiddleware>(); builder.Services.AddSingleton <IExceptionToResponseMapper, T>(); return(builder); }
public static IDrexBuilder AddSqlServer <TMyDbContext>(this IDrexBuilder builder, Func <ISqlServerOptionsBuilder, ISqlServerOptionsBuilder> buildOptions) where TMyDbContext : DbContext { var mongoOptions = buildOptions(new SqlServerOptionsBuilder()).Build(); return(builder.AddSqlServer <TMyDbContext>(mongoOptions)); }
public static IDrexBuilder AddServiceClient <T>(this IDrexBuilder builder, string serviceName, RestEaseOptions options, ConsulOptions consulOptions, FabioOptions fabioOptions, HttpClientOptions httpClientOptions) where T : class { return(builder.AddServiceClient <T>(serviceName, options, b => b.AddFabio(fabioOptions, consulOptions, httpClientOptions))); }
public static TModel GetOptions <TModel>(this IDrexBuilder builder, string settingsSectionName) where TModel : new() { using var serviceProvider = builder.Services.BuildServiceProvider(); var configuration = serviceProvider.GetService <IConfiguration>(); return(configuration.GetOptions <TModel>(settingsSectionName)); }
public static IDrexBuilder AddWebApiSwaggerDocs(this IDrexBuilder builder, string sectionName = SectionName) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } return(builder.AddWebApiSwaggerDocs(b => b.AddSwaggerDocs(sectionName))); }
public static IDrexBuilder AddCommandHandlers(this IDrexBuilder builder) { builder.Services.Scan(s => s.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies()) .AddClasses(c => c.AssignableTo(typeof(ICommandHandler <>))) .AsImplementedInterfaces() .WithTransientLifetime()); return(builder); }
public static IDrexBuilder AddFabio(this IDrexBuilder builder, Func <IFabioOptionsBuilder, IFabioOptionsBuilder> buildOptions, Func <IConsulOptionsBuilder, IConsulOptionsBuilder> buildConsulOptions, HttpClientOptions httpClientOptions) { var fabioOptions = buildOptions(new FabioOptionsBuilder()).Build(); return(builder.AddFabio(fabioOptions, httpClientOptions, b => b.AddConsul(buildConsulOptions, httpClientOptions))); }
public static IDrexBuilder AddDistributedAccessTokenValidator(this IDrexBuilder builder) { if (!builder.TryRegister(RegistryName)) { return(builder); } builder.Services.AddSingleton <IAccessTokenService, DistributedAccessTokenService>(); return(builder); }
public static IDrexBuilder AddMongo(this IDrexBuilder builder, string sectionName = SectionName) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var mongoOptions = builder.GetOptions <MongoDbOptions>(sectionName); return(builder.AddMongo(mongoOptions)); }
public static IDrexBuilder AddRedis(this IDrexBuilder builder, string sectionName = SectionName) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var options = builder.GetOptions <RedisOptions>(sectionName); return(builder.AddRedis(options)); }
public static IDrexBuilder AddServiceClient <T>(this IDrexBuilder builder, string serviceName, Func <IRestEaseOptionsBuilder, IRestEaseOptionsBuilder> buildOptions, Func <IConsulOptionsBuilder, IConsulOptionsBuilder> buildConsulOptions, Func <IFabioOptionsBuilder, IFabioOptionsBuilder> buildFabioOptions, HttpClientOptions httpClientOptions) where T : class { var options = buildOptions(new RestEaseOptionsBuilder()).Build(); return(builder.AddServiceClient <T>(serviceName, options, b => b.AddFabio(buildFabioOptions, buildConsulOptions, httpClientOptions))); }
public static IDrexBuilder AddJwt(this IDrexBuilder builder, string sectionName = SectionName, Action <JwtBearerOptions> optionsFactory = null) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var options = builder.GetOptions <JwtOptions>(sectionName); return(builder.AddJwt(options, optionsFactory)); }
public static IDrexBuilder AddRabbitMq <TContext>(this IDrexBuilder builder, Func <IRabbitMqOptionsBuilder, IRabbitMqOptionsBuilder> buildOptions, Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins = null, Func <IRedisOptionsBuilder, IRedisOptionsBuilder> buildRedisOptions = null) where TContext : class, new() { var options = buildOptions(new RabbitMqOptionsBuilder()).Build(); return(buildRedisOptions is null ? builder.AddRabbitMq <TContext>(options, plugins) : builder.AddRabbitMq <TContext>(options, plugins, b => b.AddRedis(buildRedisOptions))); }
public static IDrexBuilder AddMongoRepository <TEntity, TIdentifiable>(this IDrexBuilder 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 IDrexBuilder AddConsul(this IDrexBuilder builder, string sectionName = SectionName, string httpClientSectionName = "httpClient") { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var consulOptions = builder.GetOptions <ConsulOptions>(sectionName); var httpClientOptions = builder.GetOptions <HttpClientOptions>(httpClientSectionName); return(builder.AddConsul(consulOptions, httpClientOptions)); }
public static IDrexBuilder AddMetrics(this IDrexBuilder builder, Func <IMetricsOptionsBuilder, IMetricsOptionsBuilder> buildOptions, string appSectionName = AppSectionName) { if (string.IsNullOrWhiteSpace(appSectionName)) { appSectionName = AppSectionName; } var metricsOptions = buildOptions(new MetricsOptionsBuilder()).Build(); var appOptions = builder.GetOptions <AppOptions>(appSectionName); return(builder.AddMetrics(metricsOptions, appOptions)); }
public static IDrexBuilder AddSqlServer <TMyDbContext>(this IDrexBuilder builder, string sectionName = SectionName) where TMyDbContext : DbContext { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } var mongoOptions = builder.GetOptions <SqlServerOptions>(sectionName); return(builder.AddSqlServer <TMyDbContext>(mongoOptions)); }