public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder)
        {
            builder.Services
            .AddSingleton <IRequestStorage, RequestStorage>()
            .AddSingleton <IStoryRequestStorage, StoryRequestStorage>()
            .AddSingleton <IIdGenerator, IdGenerator>()
            .AddSingleton <RequestTypeMetricsMiddleware>()
            .AddSingleton <IClock, UtcClock>()
            .AddScoped <IMessageBroker, MessageBroker>()
            .AddScoped <IStoryRepository, StoryMongoRepository>()
            .AddScoped <IStoryRatingRepository, StoryRatingMongoRepository>()
            .AddScoped <IUserRepository, UserMongoRepository>()
            .AddScoped <IUsersApiClient, UsersApiHttpClient>()
            .AddTransient <IAppContextFactory, AppContextFactory>()
            .AddTransient(ctx => ctx.GetRequiredService <IAppContextFactory>().Create())
            .AddDomainEvents()
            .AddGrpc();

            if (builder.GetOptions <PrometheusOptions>("prometheus").Enabled)
            {
                builder.Services.TryDecorate(typeof(ICommandHandler <>), typeof(MetricsCommandHandlerDecorator <>));
            }

            if (builder.GetOptions <JaegerOptions>("jaeger").Enabled)
            {
                builder.Services.TryDecorate(typeof(ICommandHandler <>), typeof(TracingCommandHandlerDecorator <>));
            }

            builder.Services.TryDecorate(typeof(ICommandHandler <>), typeof(LoggingCommandHandlerDecorator <>));
            builder.Services.TryDecorate(typeof(IEventHandler <>), typeof(LoggingEventHandlerDecorator <>));


            builder.Services.TryDecorate(typeof(ICommandHandler <>), typeof(OutboxCommandHandlerDecorator <>));
            builder.Services.TryDecorate(typeof(IEventHandler <>), typeof(OutboxEventHandlerDecorator <>));

            builder
            .AddErrorHandler <ExceptionToResponseMapper>()
            .AddExceptionToMessageMapper <ExceptionToMessageMapper>()
            .AddQueryHandlers()
            .AddInMemoryQueryDispatcher()
            .AddHttpClient()
            .AddConsul()
            .AddFabio()
            .AddRabbitMq(plugins: p => p.AddJaegerRabbitMqPlugin())
            .AddMessageOutbox(o => o.AddMongo())
            .AddMongo()
            .AddRedis()
            .AddPrometheus()
            .AddJaeger()
            .AddMongoRepository <StoryDocument, long>("stories")
            .AddMongoRepository <UserDocument, Guid>("users")
            .AddWebApiSwaggerDocs()
            .AddCertificateAuthentication()
            .AddSecurity();

            builder.Services.AddScoped <LogContextMiddleware>()
            .AddSingleton <ICorrelationIdFactory, CorrelationIdFactory>();

            return(builder);
        }
Пример #2
0
        public static IConveyBuilder AddJwt(this IConveyBuilder builder, string sectionName = SectionName,
                                            string redisSectionName = "redis")
        {
            var options      = builder.GetOptions <JwtOptions>(sectionName);
            var redisOptions = builder.GetOptions <RedisOptions>(redisSectionName);

            return(builder.AddJwt(options, b => b.AddRedis(redisOptions)));
        }
Пример #3
0
        public static IConveyBuilder AddConsul(this IConveyBuilder builder, string sectionName = SectionName,
                                               string httpClientSectionName = "httpClient")
        {
            var consulOptions     = builder.GetOptions <ConsulOptions>(sectionName);
            var httpClientOptions = builder.GetOptions <HttpClientOptions>(httpClientSectionName);

            return(builder.AddConsul(consulOptions, httpClientOptions));
        }
Пример #4
0
        public static IConveyBuilder AddRabbitMq <TContext>(this IConveyBuilder builder, string sectionName = SectionName,
                                                            string redisSectionName = "redis", Func <IRabbitMqPluginRegister, IRabbitMqPluginRegister> plugins = null)
            where TContext : class, new()
        {
            var options      = builder.GetOptions <RabbitMqOptions>(sectionName);
            var redisOptions = builder.GetOptions <RedisOptions>(redisSectionName);

            return(builder.AddRabbitMq <TContext>(options, plugins, b => b.AddRedis(redisOptions)));
        }
Пример #5
0
        internal static IConveyBuilder AddEmailSender(this IConveyBuilder builder)
        {
            var emailOptions = builder.GetOptions <EmailOptions>("EmailOptions");
            var urlOptions   = builder.GetOptions <UrlOptions>("UrlOptions");

            builder.Services.AddSingleton(emailOptions);
            builder.Services.AddSingleton <IUrlOptions>(urlOptions);
            builder.Services.AddScoped <IEmailService, EmailService>();
            builder.Services.AddScoped <IRazorViewToStringRenderer, RazorViewToStringRenderer>();

            return(builder);
        }
Пример #6
0
        public static IConveyBuilder AddConsul(this IConveyBuilder 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));
        }
Пример #7
0
        public static IConveyBuilder AddMongo(this IConveyBuilder builder, string sectionName = SectionName,
                                              IMongoDbSeeder seeder = null)
        {
            var mongoOptions = builder.GetOptions <MongoDbOptions>(sectionName);

            return(builder.AddMongo(mongoOptions, seeder));
        }
        public static IConveyBuilder AddQoSViolationHelpers(this IConveyBuilder builder)
        {
            var qoSTrackingOptions = builder.GetOptions <QoSTrackingOptions>(SectionName);

            if (!qoSTrackingOptions.Enabled)
            {
                return(builder);
            }

            builder.Services.AddSingleton(qoSTrackingOptions);

            if (qoSTrackingOptions.EnabledTracing)
            {
                builder.Services.AddTransient <IQoSViolationMetricsRegistry, QoSViolationMetricsRegistry>();
                builder.Services.AddSingleton <IQoSViolateRaiser, QoSViolateTracerRaiser>();
            }
            else
            {
                builder.Services.AddSingleton <IQoSViolateRaiser, QoSViolateSimpleRaiser>();

                ITracer dummyTracer = new Tracer.Builder(Assembly.GetEntryAssembly().FullName)
                                      .WithReporter(new NoopReporter())
                                      .WithSampler(new ConstSampler(false))
                                      .Build();
                builder.Services.AddSingleton(dummyTracer);
            }

            return(builder);
        }
Пример #9
0
        public static IConveyBuilder AddRabbitMq(this IConveyBuilder 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))
            {
                Console.WriteLine("NOPE");
                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);
Пример #10
0
        public static IConveyBuilder AddOcsClient(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (string.IsNullOrEmpty(sectionName))
            {
                sectionName = SectionName;
            }

            var ocsOptions = builder.GetOptions <OcsOptions>(sectionName);

            if (string.IsNullOrEmpty(ocsOptions.InternalHttpClientName))
            {
                ocsOptions.InternalHttpClientName = "OcsClient";
            }

            builder.Services.AddSingleton(ocsOptions);
            builder.Services.AddHttpClient(ocsOptions.InternalHttpClientName, c =>
            {
                c.BaseAddress = new Uri(ocsOptions.StorageUrl);
                c.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("OcsClient"));
                c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json));
            });
            builder.Services.AddTransient <IRequestHandler, RequestHandler.RequestHandler>();
            builder.Services.AddTransient <IOcsClient, OcsClient>();
            builder.Services.AddTransient <IAuthManager, AuthManager>();

            return(builder);
        }
Пример #11
0
        public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder)
        {
            var requestsOptions = builder.GetOptions <RequestsOptions>("requests");

            builder.Services.AddSingleton(requestsOptions);
            builder.Services.AddTransient <ICommandHandler <ICommand>, GenericCommandHandler <ICommand> >()
            .AddTransient <IEventHandler <IEvent>, GenericEventHandler <IEvent> >()
            .AddTransient <IEventHandler <IRejectedEvent>, GenericRejectedEventHandler <IRejectedEvent> >()
            .AddTransient <IHubService, HubService>()
            .AddTransient <IHubWrapper, HubWrapper>()
            .AddSingleton <IOperationsService, OperationsService>();
            builder.Services.AddGrpc();

            return(builder
                   .AddErrorHandler <ExceptionToResponseMapper>()
                   .AddJwt()
                   .AddCommandHandlers()
                   .AddEventHandlers()
                   .AddQueryHandlers()
                   .AddHttpClient()
                   .AddConsul()
                   .AddFabio()
                   .AddRabbitMq(plugins: p => p.AddJaegerRabbitMqPlugin())
                   .AddMongo()
                   .AddRedis()
                   .AddMetrics()
                   .AddJaeger()
                   .AddRedis()
                   .AddSignalR()
                   .AddWebApiSwaggerDocs()
                   .AddSecurity());
        }
Пример #12
0
    public static IConveyBuilder AddHttpClient(this IConveyBuilder builder, string clientName = "convey",
                                               IEnumerable <string> maskedRequestUrlParts     = null, string sectionName = SectionName,
                                               Action <IHttpClientBuilder> httpClientBuilder  = null)
    {
        if (string.IsNullOrWhiteSpace(sectionName))
        {
            sectionName = SectionName;
        }

        if (!builder.TryRegister(RegistryName))
        {
            return(builder);
        }

        if (string.IsNullOrWhiteSpace(clientName))
        {
            throw new ArgumentException("HTTP client name cannot be empty.", nameof(clientName));
        }

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

        if (maskedRequestUrlParts is not null && options.RequestMasking is not null)
        {
            options.RequestMasking.UrlParts = maskedRequestUrlParts;
        }

        bool registerCorrelationContextFactory;
        bool registerCorrelationIdFactory;

        using (var scope = builder.Services.BuildServiceProvider().CreateScope())
        {
            registerCorrelationContextFactory = scope.ServiceProvider.GetService <ICorrelationContextFactory>() is null;
            registerCorrelationIdFactory      = scope.ServiceProvider.GetService <ICorrelationIdFactory>() is null;
        }

        if (registerCorrelationContextFactory)
        {
            builder.Services.AddSingleton <ICorrelationContextFactory, EmptyCorrelationContextFactory>();
        }

        if (registerCorrelationIdFactory)
        {
            builder.Services.AddSingleton <ICorrelationIdFactory, EmptyCorrelationIdFactory>();
        }

        builder.Services.AddSingleton(options);
        builder.Services.AddSingleton <IHttpClientSerializer, SystemTextJsonHttpClientSerializer>();
        var clientBuilder = builder.Services.AddHttpClient <IHttpClient, ConveyHttpClient>(clientName);

        httpClientBuilder?.Invoke(clientBuilder);

        if (options.RequestMasking?.Enabled == true)
        {
            builder.Services.Replace(ServiceDescriptor
                                     .Singleton <IHttpMessageHandlerBuilderFilter, ConveyHttpLoggingFilter>());
        }

        return(builder);
    }
Пример #13
0
        public static IConveyBuilder AddWebApi(this IConveyBuilder builder, Action <IMvcCoreBuilder> configureMvc = null,
                                               IJsonSerializer jsonSerializer = null, string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            if (jsonSerializer is null)
            {
                var factory = new Open.Serialization.Json.Newtonsoft.JsonSerializerFactory(new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    Converters       = { new StringEnumConverter(true) }
                });
                jsonSerializer = factory.GetSerializer();
            }

            if (jsonSerializer.GetType().Namespace?.Contains("Newtonsoft") == true)
            {
                builder.Services.Configure <KestrelServerOptions>(o => o.AllowSynchronousIO = true);
            }

            builder.Services.AddSingleton(jsonSerializer);
            builder.Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            builder.Services.AddSingleton(new WebApiEndpointDefinitions());
            var options = builder.GetOptions <WebApiOptions>(sectionName);

            builder.Services.AddSingleton(options);
            _bindRequestFromRoute = options.BindRequestFromRoute;

            var mvcCoreBuilder = builder.Services
                                 .AddLogging()
                                 .AddMvcCore();

            mvcCoreBuilder.AddMvcOptions(o =>
            {
                o.OutputFormatters.Clear();
                o.OutputFormatters.Add(new JsonOutputFormatter(jsonSerializer));
                o.InputFormatters.Clear();
                o.InputFormatters.Add(new JsonInputFormatter(jsonSerializer));
            })
            .AddDataAnnotations()
            .AddApiExplorer()
            .AddAuthorization();

            configureMvc?.Invoke(mvcCoreBuilder);

            builder.Services.Scan(s =>
                                  s.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies())
                                  .AddClasses(c => c.AssignableTo(typeof(IRequestHandler <,>)))
                                  .AsImplementedInterfaces()
                                  .WithTransientLifetime());

            builder.Services.AddTransient <IRequestDispatcher, RequestDispatcher>();

            return(builder);
        }
        private static IConveyBuilder AddSignalR(this IConveyBuilder builder)
        {
            var options = builder.GetOptions <SignalrOptions>("signalR");

            builder.Services.AddSingleton(options);
            var signalR = builder.Services.AddSignalR();

            if (!options.Backplane.Equals("redis", StringComparison.InvariantCultureIgnoreCase))
            {
                return(builder);
            }

            var redisOptions = builder.GetOptions <RedisOptions>("redis");

            signalR.AddRedis(redisOptions.ConnectionString);

            return(builder);
        }
Пример #15
0
    public static IConveyBuilder AddMetrics(this IConveyBuilder builder,
                                            string metricsSectionName = MetricsSectionName, string appSectionName = AppSectionName)
    {
        if (string.IsNullOrWhiteSpace(metricsSectionName))
        {
            metricsSectionName = MetricsSectionName;
        }

        if (string.IsNullOrWhiteSpace(appSectionName))
        {
            appSectionName = AppSectionName;
        }

        var metricsOptions = builder.GetOptions <MetricsOptions>(metricsSectionName);
        var appOptions     = builder.GetOptions <AppOptions>(appSectionName);

        return(builder.AddMetrics(metricsOptions, appOptions));
    }
Пример #16
0
        public static IConveyBuilder AddEfCore <TContext>(this IConveyBuilder builder)
            where TContext : DbContext
        {
            builder.Services.AddDbContext <TContext>(options =>
                                                     options.UseSqlServer(
                                                         builder.GetOptions <EfCoreOptions>("EfCoreOptions").ConnectionString
                                                         ));

            return(builder);
        }
Пример #17
0
        public static IConveyBuilder AddServiceClient <T>(this IConveyBuilder builder, string serviceName,
                                                          string sectionName           = SectionName, string consulSectionName = "consul", string fabioSectionName = "fabio",
                                                          string httpClientSectionName = "httpClient")
            where T : class
        {
            var restEaseOptions = builder.GetOptions <RestEaseOptions>(sectionName);

            return(builder.AddServiceClient <T>(serviceName, restEaseOptions,
                                                b => b.AddFabio(fabioSectionName, consulSectionName, httpClientSectionName)));
        }
        public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder)
        {
            var requestsOptions = builder.GetOptions <GumtreeOption>("gumtreeOptions");

            builder.Services.AddSingleton(requestsOptions);
            return(builder
                   .AddQueryHandlers()
                   .AddInMemoryQueryDispatcher()
                   .AddCommandHandlers()
                   .AddInMemoryCommandDispatcher());
        }
Пример #19
0
        public static IConveyBuilder AddSwaggerDocs(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

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

            return(builder.AddSwaggerDocs(options));
        }
        public static IConveyBuilder AddMinio(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

            var blobStorageOptions = builder.GetOptions <MinioOptions>(sectionName);

            return(builder.AddMinio(blobStorageOptions));
        }
Пример #21
0
        public static IConveyBuilder AddMongo(this IConveyBuilder 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));
        }
Пример #22
0
        public static IConveyBuilder AddJaeger(this IConveyBuilder builder, string sectionName = SectionName,
                                               Action <IOpenTracingBuilder> openTracingBuilder = null)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

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

            return(builder.AddJaeger(options, sectionName, openTracingBuilder));
        }
Пример #23
0
        public static IConveyBuilder AddMongo(this IConveyBuilder builder, string sectionName = SectionName,
                                              IMongoDbSeeder seeder = null)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

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

            return(builder.AddMongo(mongoOptions, seeder));
        }
Пример #24
0
        public static IConveyBuilder AddJwt(this IConveyBuilder 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));
        }
Пример #25
0
    public static IConveyBuilder AddMetrics(this IConveyBuilder 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));
    }
Пример #26
0
        public static IConveyBuilder AddHttpClient(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

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

            builder.Services.AddSingleton(options);
            builder.Services.AddHttpClient <IHttpClient, ConveyHttpClient>();

            return(builder);
        }
Пример #27
0
        public static IConveyBuilder AddWebApi(this IConveyBuilder builder, Action <IMvcCoreBuilder> configureMvc = null,
                                               IJsonFormatterResolver jsonFormatterResolver = null, IEnumerable <IJsonFormatter> jsonFormatters = null,
                                               string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            JsonFormatterResolver = jsonFormatterResolver ?? ConveyFormatterResolver.Instance;
            if (!(jsonFormatters is null) && jsonFormatterResolver is ConveyFormatterResolver)
            {
                ConveyFormatterResolver.Formatters.AddRange(jsonFormatters);
            }

            builder.Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            builder.Services.AddSingleton(new WebApiEndpointDefinitions());
            var options = builder.GetOptions <WebApiOptions>(sectionName);

            builder.Services.AddSingleton(options);
            _bindRequestFromRoute = options.BindRequestFromRoute;

            var mvcCoreBuilder = builder.Services
                                 .AddLogging()
                                 .AddMvcCore();

            mvcCoreBuilder.AddMvcOptions(o =>
            {
                o.OutputFormatters.Clear();
                o.OutputFormatters.Add(new JsonOutputFormatter(JsonFormatterResolver));
                o.InputFormatters.Clear();
                o.InputFormatters.Add(new JsonInputFormatter(JsonFormatterResolver));
            })
            .AddDataAnnotations()
            .AddApiExplorer()
            .AddAuthorization();

            configureMvc?.Invoke(mvcCoreBuilder);

            builder.Services.Scan(s =>
                                  s.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies())
                                  .AddClasses(c => c.AssignableTo(typeof(IRequestHandler <,>)))
                                  .AsImplementedInterfaces()
                                  .WithTransientLifetime());

            builder.Services.AddTransient <IRequestDispatcher, RequestDispatcher>();

            return(builder);
        }
Пример #28
0
        public static IConveyBuilder AddMessageOutbox(this IConveyBuilder builder, string sectionName = SectionName)
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

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

            builder.Services.AddSingleton(options);
            builder.AddMongo();
            builder.AddMongoRepository <OutboxMessage, Guid>("outbox");
            builder.Services.AddTransient <IMessageOutbox, MongoMessageOutbox>();
            builder.Services.AddHostedService <OutboxProcessor>();
            return(builder);
        }
Пример #29
0
    public static IConveyBuilder AddPrometheus(this IConveyBuilder builder)
    {
        var prometheusOptions = builder.GetOptions <PrometheusOptions>("prometheus");

        builder.Services.AddSingleton(prometheusOptions);
        if (!prometheusOptions.Enabled)
        {
            return(builder);
        }

        builder.Services.AddHostedService <PrometheusJob>();
        builder.Services.AddSingleton <PrometheusMiddleware>();
        builder.Services.AddSystemMetrics();

        return(builder);
    }
Пример #30
0
        public static IConveyBuilder AddCertificateAuthentication(this IConveyBuilder builder,
                                                                  string sectionName = SectionName, Type permissionValidatorType = null)
        {
            var options = builder.GetOptions <SecurityOptions>(sectionName);

            builder.Services.AddSingleton(options);
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            if (options.Certificate is null || !options.Certificate.Enabled)
            {
                return(builder);
            }

            if (permissionValidatorType is {})