Created
April 29, 2016 21:17
-
-
Save kdowswell/37ff28573f5468d4236e03d3f511c4b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidatorHandler<TRequest, TResponse> | |
: IRequestHandler<TRequest, TResponse> | |
where TRequest : IRequest<TResponse> | |
{ | |
private readonly IRequestHandler<TRequest, TResponse> _inner; | |
private readonly IValidator<TRequest> _validator; | |
public ValidatorHandler(IRequestHandler<TRequest, TResponse> inner, | |
IValidator<TRequest> validator) | |
{ | |
_inner = inner; | |
_validator = validator; | |
} | |
public TResponse Handle(TRequest request) | |
{ | |
var validationResult = _validator.Validate(request); | |
if (!validationResult.IsValid) | |
{ | |
throw new ValidationException(validationResult.Errors); | |
} | |
return _inner.Handle(request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment