diff --git a/.travis.yml b/.travis.yml index 317d9a1..a94207d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ env: global: - - PACKAGE_VERSION="3.0.0-rc2" + - PACKAGE_VERSION="3.0.0-rc3" - PACKAGE_ICON="https://www.enbiso.com/logo.svg" - PACKAGE_PROJECT="https://nlib.enbiso.com" - PACKAGE_REPO="https://github.com/enbiso/Enbiso.NLib" diff --git a/Enbiso.NLib.Cqrs/CommandValidator.cs b/Enbiso.NLib.Cqrs/CommandValidator.cs index 64c2676..51d85f0 100644 --- a/Enbiso.NLib.Cqrs/CommandValidator.cs +++ b/Enbiso.NLib.Cqrs/CommandValidator.cs @@ -21,8 +21,11 @@ public ValidatorBehavior(IEnumerable> validators) public async Task Handle(TCommand request, CancellationToken cancellationToken, RequestHandlerDelegate next) { - var failures = _validators.SelectMany(v => v.Validate(request)).Where(error => error != null).ToArray(); + var validatorTasks = _validators.Select(v => v.Validate(request)).ToArray(); + await Task.WhenAll(validatorTasks); + var failures = validatorTasks.SelectMany(t => t.Result).Where(error => error != null).ToArray(); + if (failures.Any()) throw new CommandValidationException(typeof(TCommand), failures); @@ -38,7 +41,7 @@ public ValidatorBehavior(IEnumerable> validators) public interface ICommandValidator where TCommand: IBaseCommand { - IEnumerable Validate(TCommand command); + Task> Validate(TCommand command); } ///