Skip to content
Permalink
Browse files

Async command validator

  • Loading branch information...
farajfarook committed Nov 8, 2019
1 parent 92e4e1c commit 28fef0f807d284be52976c26125e64ddb1657371
Showing with 6 additions and 3 deletions.
  1. +1 −1 .travis.yml
  2. +5 −2 Enbiso.NLib.Cqrs/CommandValidator.cs
@@ -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"
@@ -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);

@@ -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>

0 comments on commit 28fef0f

Please sign in to comment.
You can’t perform that action at this time.