Ejemplo n.º 1
0
        private async Task ExecuteCommandAsync <TCommand>(TCommand command, IExecutionContext executionContext) where TCommand : ICommand
        {
            if (command == null)
            {
                return;
            }

            var cx = await CreateExecutionContextAsync(executionContext);

            var handler = _commandHandlerFactory.CreateAsyncHandler <TCommand>();

            if (handler == null)
            {
                throw new MissingHandlerMappingException(typeof(TCommand));
            }

            try
            {
                _modelValidationService.Validate(command);
                _executePermissionValidationService.Validate(command, handler, cx);
                await handler.ExecuteAsync(command, cx);
            }
            catch (Exception ex)
            {
                await _commandLogService.LogFailedAsync(command, cx, ex);

                throw;
            }

            await _commandLogService.LogAsync(command, cx);
        }