Ejemplo n.º 1
0
        private async Task ExecuteMiddlewareAsync(CommandContext context, MariCommandsOptions config = null, bool addFilter = false)
        {
            var services = new ServiceCollection();

            services.AddLogging();

            if (config.HasContent())
            {
                services.AddSingleton <IOptions <MariCommandsOptions> >(config);
            }
            else
            {
                services.AddOptions <MariCommandsOptions>();
            }

            services.AddSingleton <IFilterProvider, FilterProvider>();

            if (addFilter)
            {
                services.AddFilterFactory <ResultFilterFactory, ICommandResultFilter, CommandResultDelegate>();
                services.AddSingleton <SingletonDependency>();
            }

            var provider = services.BuildServiceProvider(true);

            context.ServiceScopeFactory = provider.GetRequiredService <IServiceScopeFactory>();

            var app = new TestCommandApplicationBuilder(provider);

            app.UseCommandExecutor();

            var commandDelegate = app.Build();

            await commandDelegate(context);
        }
        private async Task ExecuteMiddlewareAsync(CommandContext context, IArgumentParser argumentParser, Action <MariCommandsOptions> config = null)
        {
            var services = new ServiceCollection();

            services.AddLogging();

            services.AddOptions <MariCommandsOptions>();

            if (config.HasContent())
            {
                services.Configure(config);
            }

            services.AddSingleton <IArgumentParser>(argumentParser);

            var provider = services.BuildServiceProvider(true);

            context.ServiceScopeFactory = provider.GetRequiredService <IServiceScopeFactory>();

            var app = new TestCommandApplicationBuilder(provider);

            app.UseParser();

            var commandDelegate = app.Build();

            await commandDelegate(context);
        }
        private async Task ExecuteMiddlewareAsync(CommandContext context)
        {
            var services = new ServiceCollection();

            services.AddLogging();

            var provider = services.BuildServiceProvider(true);

            context.ServiceScopeFactory = provider.GetRequiredService <IServiceScopeFactory>();

            var app = new TestCommandApplicationBuilder(provider);

            app.UseParamPreconditioner();

            var commandDelegate = app.Build();

            await commandDelegate(context);
        }
Ejemplo n.º 4
0
        private async Task ExecuteMiddlewareAsync(CommandContext context, IModuleCache moduleCache)
        {
            var services = new ServiceCollection();

            services.AddLogging();

            services.AddSingleton <IModuleCache>(moduleCache);

            var provider = services.BuildServiceProvider(true);

            context.ServiceScopeFactory = provider.GetRequiredService <IServiceScopeFactory>();

            var app = new TestCommandApplicationBuilder(provider);

            app.UseStringMatcher();

            var commandDelegate = app.Build();

            await commandDelegate(context);
        }