コード例 #1
0
        public static IBrighterHandlerBuilder AddServiceActivator(
            this IServiceCollection services,
            Action <ServiceActivatorOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new ServiceActivatorOptions();

            configure?.Invoke(options);
            services.AddSingleton(options);
            services.AddSingleton <IBrighterOptions>(options);

            services.AddSingleton <IDispatcher>(BuildDispatcher);

            return(ServiceCollectionExtensions.BrighterHandlerBuilder(services, options));
        }
コード例 #2
0
        public static IServiceActivatorBuilder AddServiceActivator(
            this IServiceCollection services,
            Action <ServiceActivatorOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new ServiceActivatorOptions();

            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);
            }

            var mapperRegistry = new ServiceCollectionMessageMapperRegistry(services, options.MapperLifetime);

            services.AddSingleton <ServiceCollectionMessageMapperRegistry>(mapperRegistry);


            services.AddSingleton <IDispatcher>(BuildDispatcher);

            return(new ServiceCollectionServiceActivatorBuilder(services, subscriberRegistry, mapperRegistry));
        }