Пример #1
0
        private void RegisterGenericCommandInternal <TCommand>(CommandLineCommand <TOption, object> command)
            where TCommand : Abstractions.Command.Command
        {
            var cmdConfigurator = (Command <TOption>)(Abstractions.Command.Command)(ActivatorUtilities.GetServiceOrCreateInstance <TCommand>(m_serviceProvider));

            cmdConfigurator.OnConfigure(command);

            command.OnExecuting((Action <TOption>)cmdConfigurator.OnExecute);
            command.OnExecutingAsync((Func <TOption, CancellationToken, Task>)cmdConfigurator.OnExecuteAsync);
        }
Пример #2
0
        private void RegisterNonGenericCommandInternal <TCommand>(CommandLineCommand <TOption, object> command)
            where TCommand : Abstractions.Command.Command
        {
            var cmdConfigurator = ActivatorUtilities.GetServiceOrCreateInstance <TCommand>(m_serviceProvider);

            cmdConfigurator.OnConfigure(command);

            command.OnExecuting(cmdConfigurator.OnExecute);
            command.OnExecutingAsync(cmdConfigurator.OnExecuteAsync);
        }
        /// <summary>
        /// Registers a command type
        /// </summary>
        /// <typeparam name="TCommandOption">Command type, must be inherit <see cref="Command{TOptions, TCommandOptions}"/></typeparam>
        public void RegisterCommand <TCommand>()
            where TCommand : Command <TCommandOption>
        {
            var cmdConfigurator = m_containerResolver.Resolve <TCommand>();

            var command = new CommandLineCommand <TCommandOption, object>(m_parserOptions, m_resolverFactory, m_containerResolver, m_commandOption);

            cmdConfigurator.OnConfigure(command);

            command.OnExecuting((Action <TCommandOption>)cmdConfigurator.OnExecute);

            m_commands.Add(command);
        }