Exemplo n.º 1
0
        /// <summary>
        /// Adds and configures the consistence services for the consistency.
        /// </summary>
        /// <param name="services">The services available in the application.</param>
        /// <param name="setupAction">An action to configure the <see cref="CafOptions" />.</param>
        /// <returns>An <see cref="CafBuilder" /> for application services.</returns>
        public static void AddIntegrationEventBus(this IServiceCollection services, Action <IntegrationEventBusOptions> setupAction)
        {
            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            ServiceCollection = services;
            services.TryAddSingleton <IConsumerRegister, ConsumerRegister>();

            //Processors
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IProcessingServer, ConsumerRegister>());

            //Options and extension service
            var options = new IntegrationEventBusOptions();

            setupAction(options);
            foreach (var serviceExtension in options.Extensions)
            {
                serviceExtension.AddServices(services);
            }
            services.Configure(setupAction);
            if (options.IConsumerErrHandler != null)
            {
                services.Replace(ServiceDescriptor.Singleton(typeof(IConsumerErrHandler), options.IConsumerErrHandler));
            }
            //Startup and Hosted
            services.AddSingleton <Bootstrapper>();
            services.AddHostedService <Bootstrapper>();
        }
Exemplo n.º 2
0
 public ConsumerRegister(ILogger <ConsumerRegister> logger, IServiceScopeFactory serviceScopeFactory,
                         IConsumerClientFactory consumerClientFactory, IIntegrationEventBus integrationEventBus,
                         IConsumerErrHandler consumerErrHandler, IOptions <IntegrationEventBusOptions> options)
 {
     _logger = logger;
     _serviceScopeFactory   = serviceScopeFactory;
     _consumerClientFactory = consumerClientFactory;
     _integrationEventBus   = integrationEventBus;
     _options            = options.Value;
     _consumerErrHandler = consumerErrHandler;
     _cts = new CancellationTokenSource();
 }