public static IBrighterHandlerBuilder AddBrighter(this IServiceCollection services, Action <BrighterOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new BrighterOptions();

            configure?.Invoke(options);
            services.AddSingleton(options);

            var subscriberRegistry = new ServiceCollectionSubscriberRegistry(services);

            services.AddSingleton <ServiceCollectionSubscriberRegistry>(subscriberRegistry);

            if (options.HandlerLifetime == ServiceLifetime.Scoped)
            {
                services.AddScoped <IAmACommandProcessor>(BuildCommandProcessor);
            }
            else
            {
                services.AddSingleton <IAmACommandProcessor>(BuildCommandProcessor);
            }

            return(new ServiceCollectionBrighterBuilder(services, subscriberRegistry));
        }
Example #2
0
        public static IBrighterHandlerBuilder BrighterHandlerBuilder(IServiceCollection services, BrighterOptions options)
        {
            var subscriberRegistry = new ServiceCollectionSubscriberRegistry(services);

            services.AddSingleton <ServiceCollectionSubscriberRegistry>(subscriberRegistry);

            services.Add(new ServiceDescriptor(typeof(IAmACommandProcessor), BuildCommandProcessor, options.CommandProcessorLifetime));

            var mapperRegistry = new ServiceCollectionMessageMapperRegistry(services);

            services.AddSingleton <ServiceCollectionMessageMapperRegistry>(mapperRegistry);

            return(new ServiceCollectionBrighterBuilder(services, subscriberRegistry, mapperRegistry));
        }
 public ServiceCollectionBrighterBuilder(IServiceCollection services, ServiceCollectionSubscriberRegistry serviceCollectionSubscriberRegistry)
 {
     Services = services;
     _serviceCollectionSubscriberRegistry = serviceCollectionSubscriberRegistry;
 }
 public ServiceCollectionBrighterBuilder(IServiceCollection services, ServiceCollectionSubscriberRegistry serviceCollectionSubscriberRegistry, ServiceCollectionMessageMapperRegistry mapperRegistry)
 {
     Services = services;
     _serviceCollectionSubscriberRegistry = serviceCollectionSubscriberRegistry;
     _mapperRegistry = mapperRegistry;
 }