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));
        }
Exemple #2
0
        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 <IBrighterOptions>(options);

            return(BrighterHandlerBuilder(services, options));
        }
Exemple #3
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));
        }