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

            var options = new DarkerOptions();

            configure?.Invoke(options);

            var registry = new AspNetHandlerRegistry(services);
            var factory  = new AspNetHandlerFactory(services);

            registry.RegisterFromAssemblies(options.DiscoverQueriesAndHandlersFromAssemblies);

            var builder = QueryProcessorBuilder.With()
                          .Handlers(registry, factory, registry, factory)
                          .QueryContextFactory(options.QueryContextFactory);

            var queryProcessor = builder.Build();

            services.AddSingleton(queryProcessor);

            return((QueryProcessorBuilder)builder);
        }
コード例 #2
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 registry = new AspNetHandlerRegistry(services, options.HandlerLifetime);
            var factory  = new AspNetHandlerFactory(services);

            var builder = QueryProcessorBuilder.With()
                          .Handlers(registry, factory, registry, factory)
                          .QueryContextFactory(options.QueryContextFactory);

            var queryProcessor = builder.Build();

            services.AddSingleton(queryProcessor);

            return(new AspNetHandlerBuilder(services, registry, (QueryProcessorBuilder)builder));
        }