public static ServiceComponentsHostBuilder AddHealthCheck( this ServiceComponentsHostBuilder hostBuilder, Action <IConfiguration, IHealthChecksBuilder> builder, string readinessPath = "/.well-known/ready", string livenessPath = "/.well-known/live") { return(hostBuilder .RegisterCallback((configuration, environment, app) => { app.UseHealthChecks(readinessPath, new HealthCheckOptions { Predicate = registration => registration.Tags == null || !registration.Tags.Any() || registration.Tags.Contains(ReadinessTag) }); app.UseHealthChecks(livenessPath, new HealthCheckOptions { Predicate = registration => registration.Tags == null || !registration.Tags.Any() || registration.Tags.Contains(LivenessTag) }); }) .RegisterCallback((configuration, services) => { builder(configuration, services.AddHealthChecks() .AddCheck("self", () => HealthCheckResult.Healthy(), new[] { LivenessTag })); })); }
public static ServiceComponentsHostBuilder AddRedisDistributedCache(this ServiceComponentsHostBuilder hostBuilder, string connection, string instance = default) { return(hostBuilder.RegisterCallback((configuration, services) => services.AddStackExchangeRedisCache(options => { options.InstanceName = instance; options.Configuration = connection; }))); }
public static ServiceComponentsHostBuilder AddPrometheusMetrics(this ServiceComponentsHostBuilder hostBuilder) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddPrometheusRequestMetricsService(); containerBuilder.AddPrometheusRequestMetricsBehavior(); })); }
public static ServiceComponentsHostBuilder AddBadge(this ServiceComponentsHostBuilder hostBuilder) { return(AddBadge(hostBuilder, (configuration, registry) => { registry.RegistrateLivenessBadge(); registry.RegistrateReadinessBadge(); registry.RegistrateVersionBadge(); })); }
public static ServiceComponentsHostBuilder AddLoopbackSender(this ServiceComponentsHostBuilder hostBuilder, object key = default) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddLoopbackCommandSender(key); containerBuilder.AddLoopbackQuerySender(key); containerBuilder.AddLoopbackEventPublisher(key); })); }
public static ServiceComponentsHostBuilder AddHttpSender(this ServiceComponentsHostBuilder hostBuilder, Uri endpointUri, object key = default) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddHttpCommandSender(endpointUri, key); containerBuilder.AddHttpQuerySender(endpointUri, key); containerBuilder.AddHttpEventPublisher(endpointUri, key); })); }
public static ServiceComponentsHostBuilder AddRedisDistributedCache(this ServiceComponentsHostBuilder hostBuilder, Action <ConfigurationOptions> optionsBuilder) { var opts = new ConfigurationOptions(); optionsBuilder(opts); return(hostBuilder.RegisterCallback((configuration, services) => services.AddStackExchangeRedisCache(options => { options.ConfigurationOptions = opts; }))); }
public static ServiceComponentsHostBuilder AddHttpSender(this ServiceComponentsHostBuilder hostBuilder, Func <IConfiguration, Uri> endpointUriBuilder, object key = default) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { var uri = endpointUriBuilder(context.Configuration); containerBuilder.AddHttpCommandSender(uri, key); containerBuilder.AddHttpQuerySender(uri, key); containerBuilder.AddHttpEventPublisher(uri, key); })); }
public static ServiceComponentsHostBuilder AddRedis(this ServiceComponentsHostBuilder hostBuilder, Func <IConfiguration, string> connectionStringBuilder) { hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddRedisConnection(connectionStringBuilder(context.Configuration)); containerBuilder.AddRedisDatabase(); }); return(hostBuilder); }
public static ServiceComponentsHostBuilder AddMediator(this ServiceComponentsHostBuilder hostBuilder, Assembly[] applicationAssemblies, bool addBehavior = true) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddMediator(applicationAssemblies); if (addBehavior) { containerBuilder.AddMediatorBehavior(applicationAssemblies); } })); }
public static ServiceComponentsHostBuilder AddBadge(this ServiceComponentsHostBuilder hostBuilder, Action <IConfiguration, IBadgeRegistry> builder, string pattern = ".badge") { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddBadgeService(registry => builder(context.Configuration, registry)); }) .RegisterCallback((configuration, routeBuilder) => { routeBuilder.MapControllerRoute(name: "badge", pattern: $"{pattern.TrimEnd('/')}/{{name?}}", defaults: new { controller = "Badge", action = "Get" }); })); }
public static ServiceComponentsHostBuilder AddCorrelation(this ServiceComponentsHostBuilder hostBuilder) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddCorrelationInfo(); containerBuilder.AddReceiverCorrelationLogEnricherBehavior(); containerBuilder.AddHttpReceiverCorrelationBehavior(); containerBuilder.AddHttpSenderCorrelationBehavior(); containerBuilder.AddLoopbackReceiverCorrelationBehavior(); containerBuilder.AddRabbitReceiverCorrelationBehavior(); containerBuilder.AddRabbitSenderCorrelationBehavior(); })); }
public static ServiceComponentsHostBuilder UseDefault(this ServiceComponentsHostBuilder builder, Assembly[] apiAssemblies, Assembly[] applicationAssemblies) { return(builder // Use Autofac for dependency injection .UseAutofac() // Add request binder for command, query and event deserialization .UseRequestBinder() .RegisterCallback((configuration, services) => { var mvcBuilder = services.AddControllers(options => { builder.MvcOptionsBuilderCallbacks.ForEach(action => action(options)); }); var hostAssembly = Assembly.GetEntryAssembly(); mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(hostAssembly)); mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(BadgeController).Assembly)); builder.MvcBuilderCallbacks.ForEach(x => x(mvcBuilder)); services.AddHttpContextAccessor(); services.AddHttpClient(); services.AddCors(); }) .RegisterCallback((context, containerBuilder) => { containerBuilder.RegisterType <ComputerClock>().AsImplementedInterfaces().SingleInstance(); containerBuilder.AddHttpRequestParser(); }) // Add Mediator components .AddMediator(applicationAssemblies, addBehavior: true) // Add fluent validation behavior .AddValidationBehavior(apiAssemblies) // Add request logging behavior .AddLogBehavior() // Add stopwatch behavior for measure and log execution time of command, query and event handlers .AddStopwatchBehavior() // Registers CorrelationInfo service .AddCorrelation() // Register receivers .AddReceivers() // Add loopback command, query and event senders with key 'loopback' .AddLoopbackSender("loopback") ); }
public static ServiceComponentsHostBuilder AddOpenApi(this ServiceComponentsHostBuilder builder, Action <IConfiguration, SwaggerGenOptions> generatorOptions, Action <IConfiguration, SwaggerUIOptions> uiOptions) { builder.RegisterCallback((configuration, services) => { services.AddSwaggerGen(c => { generatorOptions(configuration, c); }); }); builder.RegisterCallback((configuration, environment, app) => { app.UseSwagger(); app.UseSwaggerUI(c => uiOptions(configuration, c)); }); return(builder); }
public static ServiceComponentsHostBuilder AddReceivers(this ServiceComponentsHostBuilder hostBuilder, bool http = true, bool loopback = true) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddReceivers(); if (http) { containerBuilder.AddHttpReceivers(); } if (loopback) { containerBuilder.AddLoopbackReceivers(); } })); }
public static ServiceComponentsHostBuilder AddEndpoints(this ServiceComponentsHostBuilder builder) { builder.RegisterCallback((configuration, environment, app) => { app.UseEndpoints(endpoints => { endpoints.MapControllers(); builder.EndpointRouteBuilderCallbacks.ForEach(action => { action(configuration, endpoints); }); }); }); return(builder); }
public static ServiceComponentsHostBuilder ConfigureMvc(this ServiceComponentsHostBuilder hostBuilder, Action <IMvcBuilder> mvcBuilder) { return(hostBuilder.RegisterCallback(mvcBuilder)); }
public static ServiceComponentsHostBuilder ConfigureApp(this ServiceComponentsHostBuilder hostBuilder, Action <IConfiguration, IHostEnvironment, IApplicationBuilder> appBuilder) { return(hostBuilder.RegisterCallback(appBuilder)); }
public static ServiceComponentsHostBuilder AddValidationBehavior(this ServiceComponentsHostBuilder hostBuilder, Assembly[] apiAssemblies) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddValidationBehavior(apiAssemblies); })); }
public static ServiceComponentsHostBuilder AddRedisDistributedCache(this ServiceComponentsHostBuilder hostBuilder, string connectionString) { return(hostBuilder.RegisterCallback((configuration, services) => services.AddStackExchangeRedisCache(options => { options.ConfigurationOptions = ConfigurationOptions.Parse(connectionString); }))); }
public static ServiceComponentsHostBuilder AddStopwatchBehavior(this ServiceComponentsHostBuilder hostBuilder) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.AddStopwatchBehavior(); })); }
public static ServiceComponentsHostBuilder UseRequestBinder(this ServiceComponentsHostBuilder builder) { builder.RegisterCallback(options => options.UseRequestBinder()); return(builder); }
public static ServiceComponentsHostBuilder AddRabbit( this ServiceComponentsHostBuilder hostBuilder, Func <IConfiguration, string> connectionStringBuilder, Func <IConfiguration, string> clientNameBuilder, Func <IConfiguration, string> queueBuilder, Func <IConfiguration, string> exchangeBuilder, Func <IConfiguration, string> routingKeyBuilder = default, Func <IConfiguration, int[]> retryIntervalsBuilder = default) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { var uri = new Uri(connectionStringBuilder(context.Configuration)); var clientName = clientNameBuilder(context.Configuration); var exchange = exchangeBuilder(context.Configuration); var queue = queueBuilder(context.Configuration); var routingKey = routingKeyBuilder(context.Configuration) ?? ""; var retryIntervals = retryIntervalsBuilder(context.Configuration); // Generic connection and channel containerBuilder.AddRabbitConnection(uri, $"{clientName}-generic"); containerBuilder.AddRabbitChannel(); // Publisher connection, channel containerBuilder.AddRabbitConnection(uri, $"{clientName}-publisher", "publisher"); containerBuilder.AddRabbitChannel(key: "publisher", connectionKey: "publisher"); containerBuilder.AddRabbitEventPublisher(exchange, routingKey, channelKey: "publisher", key: "rabbit"); // Consumers containerBuilder.AddRabbitConnection(uri, $"{clientName}-consumer", "consumer"); // Add retry if defined if (retryIntervals != default) { containerBuilder.AddRabbitRetryConsumers("consumer", queue, retryIntervals, clientName); } // Add consumers for queue var consumerCount = Environment.ProcessorCount - (retryIntervals?.Length ?? 0); if (consumerCount < 1) { consumerCount = 1; } for (var i = 0; i < consumerCount; i++) { containerBuilder.AddRabbitChannel(connectionKey: "consumer", key: $"consumer-{i}"); containerBuilder.AddRabbitConsumer(queue, $"{clientName}-consumer-{i}", $"consumer-{i}", $"consumer-{i}"); } // Receivers and senders containerBuilder.AddRabbitReceivers(); containerBuilder.AddRabbitCommandSender(exchange, string.Empty, "publisher", "rabbit"); containerBuilder.AddRabbitQuerySender(exchange, string.Empty, "publisher", "rabbit"); containerBuilder.Register(context => new RabbitStartup( context.Resolve <ILogger>(), context.Resolve <ILifetimeScope>(), context.Resolve <IModel>(), queue, exchange, routingKey, retryIntervals)).AsImplementedInterfaces(); })); }
public static ServiceComponentsHostBuilder AddRabbit(this ServiceComponentsHostBuilder hostBuilder, string connectionString, string clientName, string queue, string exchange, string routingKey = "", int[] retryIntervals = default) { return(AddRabbit(hostBuilder, configuration => connectionString, configuration => clientName, configuration => queue, configuration => exchange, configuration => routingKey, configuration => retryIntervals)); }
public static ServiceComponentsHostBuilder UseAutofac(this ServiceComponentsHostBuilder builder) { builder.RegisterCallback(hostBuilder => hostBuilder.UseServiceProviderFactory(new AutofacServiceProviderFactory())); return(builder); }
public static ServiceComponentsHostBuilder UseSerilog(this ServiceComponentsHostBuilder builder) { builder.RegisterCallback(hostBuilder => hostBuilder.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration))); return(builder); }
public static ServiceComponentsHostBuilder ConfigureContainer(this ServiceComponentsHostBuilder hostBuilder, Action <HostBuilderContext, ContainerBuilder> containerBuilder) { return(hostBuilder.RegisterCallback(containerBuilder)); }
public static ServiceComponentsHostBuilder AddNHibernate(this ServiceComponentsHostBuilder hostBuilder, Func <IConfiguration, string> connectionString, Action <MappingConfiguration> mapping, Action <Configuration> exposeConfiguration) { return(hostBuilder.RegisterCallback((context, containerBuilder) => { containerBuilder.RegisterModule(new NhibernateModule(connectionString(context.Configuration), mapping, exposeConfiguration)); })); }
public static ServiceComponentsHostBuilder AddGenericController(this ServiceComponentsHostBuilder hostBuilder, string path = default) { // TODO: solve routing to path return(hostBuilder); }
public static ServiceComponentsHostBuilder UseSerilog(this ServiceComponentsHostBuilder builder, Action <HostBuilderContext, LoggerConfiguration> callback) { builder.RegisterCallback(hostBuilder => hostBuilder.UseSerilog(callback)); return(builder); }