示例#1
0
        /// <summary>
        /// Adds console commands to the service collection.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <returns>The IServiceCollection object.</returns>
        public static IServiceCollection AddConsoleCommands(this IServiceCollection services)
        {
            var commandFinder = new ConsoleCommandFinder();

            foreach (var ti in commandFinder.AvailableCommands)
            {
                services.AddTransient(ti);
            }

            services.AddSingleton(commandFinder);
            services.AddSingleton <IConsoleCommandHandler, ConsoleCommandHandler>();

            return(services);
        }
示例#2
0
 /// <summary>
 /// Initializes an instance of ConsoleCommandHandler class.
 /// </summary>
 /// <param name="services"></param>
 public ConsoleCommandHandler(IServiceProvider services)
 {
     _services             = services ?? throw new ArgumentNullException(nameof(services));
     _consoleCommandFinder = _services.GetService <ConsoleCommandFinder>();
 }