public CommandResult ExecuteCommand(Command command)
        {
            dynamic handler = FindHandlerForCommand(command);

            try
            {
                handler.Handle(command as dynamic);
                return CommandResult.Executed("Command executed successfully");
            }
            finally
            {
                _kernel.Release(handler);
            }
        }
        public Task<CommandResult> ExecuteCommandAsync(Command command)
        {
            dynamic handler = FindHandlerForCommand(command);

            try
            {
                var task = Task.Run(() =>
                    {
                        handler.Handle(command as dynamic);
                        return CommandResult.Executed("Command executed successfully");
                    });

                return task;
            }
            finally
            {
                _kernel.Release(handler);
            }
        }
 protected CommandResult Execute(Command command)
 {
     return MvcApplication.CommandExecutor.ExecuteCommand(command);
 }
 private object FindHandlerForCommand(Command command)
 {
     var handlerType = typeof(IHandleCommand<>).MakeGenericType(command.GetType());
     dynamic handler = _kernel.Get(handlerType);
     return handler;
 }