Ejemplo n.º 1
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));
        }
 public ServiceCollectionServiceActivatorBuilder(IServiceCollection services, ServiceCollectionSubscriberRegistry serviceCollectionSubscriberRegistry, ServiceCollectionMessageMapperRegistry mapperRegistry) : base((IServiceCollection)services, (ServiceCollectionSubscriberRegistry)serviceCollectionSubscriberRegistry)
 {
     _mapperRegistry = mapperRegistry;
 }