Skip to content

Commit

Permalink
Async command validator
Browse files Browse the repository at this point in the history
  • Loading branch information
farajfarook committed Nov 8, 2019
1 parent 92e4e1c commit 28fef0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .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"
Expand Down
7 changes: 5 additions & 2 deletions Enbiso.NLib.Cqrs/CommandValidator.cs
Expand Up @@ -21,8 +21,11 @@ public ValidatorBehavior(IEnumerable<ICommandValidator<TCommand>> validators)
public async Task<TResponse> Handle(TCommand request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> 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);

Expand All @@ -38,7 +41,7 @@ public ValidatorBehavior(IEnumerable<ICommandValidator<TCommand>> validators)
public interface ICommandValidator<TCommand>
where TCommand: IBaseCommand
{
IEnumerable<ValidationError> Validate(TCommand command);
Task<IEnumerable<ValidationError>> Validate(TCommand command);
}

/// <summary>
Expand Down

0 comments on commit 28fef0f

Please sign in to comment.