Esempio n. 1
0
        public static void UseStaticCommands(this IAppBuilder builder, StaticCommandsList staticCommands)
        {
            builder.UsePossibleCommands();
            builder.Services.TryAddSingleton(provider =>
            {
                ServiceProviderServiceExtensions.GetService <ILogger>(provider)
                ?.Debug("Loaded {Count} static commands: {Commands}",
                        staticCommands.StaticCommandsTypes.Count,
                        string.Join(", ", staticCommands.StaticCommandsTypes.Select(a => a.Name)));

                return(staticCommands);
            });
            builder.UseMiddleware <StaticCommandsMiddleware>();

            foreach (var command in staticCommands.StaticCommandsTypes)
            {
                builder.Services.AddScoped(command);
            }
        }
Esempio n. 2
0
        public StaticCommandsMiddleware(IServiceProvider services, UpdateDelegate next, StaticCommandsList staticCommands)
        {
            _next = next;
            var scope = services.CreateScope();

            commands = staticCommands.StaticCommandsTypes.Select(scope.ServiceProvider.GetService)
                       .Cast <IStaticCommand>()
                       .ToList();
        }