Exemplo n.º 1
0
        public static OperationsOptions AddInteractiveConsole(
            this OperationsOptions options,
            bool enabled = true)
        {
            EnsureArg.IsNotNull(options, nameof(options));
            EnsureArg.IsNotNull(options.Context, nameof(options.Context));

            if (options.Context.IsConsoleEnabled() && enabled)
            {
                Console2.WriteTextLogo();

                // needed for mediator, register console commands + handlers
                options.Context.Services.Scan(scan => scan
                                              .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                                              .AddClasses(classes => classes.Where(c => c.Name.EndsWith("ConsoleCommand", StringComparison.OrdinalIgnoreCase) || c.Name.EndsWith("ConsoleCommandEventHandler", StringComparison.OrdinalIgnoreCase)))
                                              .AsImplementedInterfaces());

                options.Context.Services.AddSingleton <Hosting.IHostedService>(sp =>
                {
                    return(new InteractiveConsoleHostedService(
                               sp.GetRequiredService <ILoggerFactory>(),
                               (IMediator)sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)),
                               sp.GetServices <IConsoleCommand>()));
                });
            }

            return(options);
        }
Exemplo n.º 2
0
        public override Task <bool> Handle(ConsoleCommandEvent <LogoConsoleCommand> request, CancellationToken cancellationToken)
        {
            Console2.WriteTextLogo();

            return(Task.FromResult(true));
        }