Ejemplo n.º 1
0
        public static IDarkerHandlerBuilder AddDarker(this IServiceCollection services,
                                                      Action <DarkerOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new DarkerOptions();

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

            var handlerRegistry = new ServiceCollectionHandlerRegistry(services, options.HandlerLifetime);

            services.AddSingleton(handlerRegistry);

            var decoratorRegistry = new ServiceCollectionDecoratorRegistry(services, options.HandlerLifetime);

            services.AddSingleton(decoratorRegistry);

            var contextBag = new DarkerContextBag();

            services.AddSingleton(contextBag);

            services.Add(new ServiceDescriptor(typeof(IQueryProcessor), BuildDarker, options.QueryProcessorLifetime));

            return(new ServiceCollectionDarkerHandlerBuilder(handlerRegistry, decoratorRegistry, contextBag));
        }
Ejemplo n.º 2
0
 public ServiceCollectionDarkerHandlerBuilder(ServiceCollectionHandlerRegistry registry,
                                              ServiceCollectionDecoratorRegistry decoratorRegistry, DarkerContextBag contextContextBag)
 {
     _registry          = registry;
     _decoratorRegistry = decoratorRegistry;
     _contextBag        = contextContextBag;
 }
Ejemplo n.º 3
0
        public static IDarkerHandlerBuilder AddDarker(this IServiceCollection services,
                                                      Action <DarkerOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new DarkerOptions();

            configure?.Invoke(options);

            var handlerRegistry = new ServiceCollectionHandlerRegistry(services, options.HandlerLifetime);

            var decoratorRegistry = new ServiceCollectionDecoratorRegistry(services, options.HandlerLifetime);

            decoratorRegistry.RegisterDefaultDecorators();

            var contextBag = new DarkerContextBag();

            services.Add(new ServiceDescriptor(typeof(IQueryProcessor), provider => new QueryProcessor(
                                                   new HandlerConfiguration(handlerRegistry, new ServiceProviderHandlerFactory(provider), decoratorRegistry,
                                                                            new ServiceProviderHandlerDecoratorFactory(provider)), options.QueryContextFactory, contextBag), options.QueryProcessorLifetime));

            return(new ServiceCollectionDarkerHandlerBuilder(handlerRegistry, decoratorRegistry, contextBag));
        }