Last active
April 18, 2016 23:17
-
-
Save dcomartin/058ff3abb049878736d50962dc529267 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
using System.Threading.Tasks; | |
using MediatR; | |
namespace ThinControllers.Demo | |
{ | |
public interface IValidationHandler<in TRequest> | |
{ | |
void Validate(TRequest request); | |
} | |
public class RequestValidationDecorator<TRequest> : | |
IAsyncRequestHandler<TRequest, Unit> where TRequest : IAsyncRequest | |
{ | |
private readonly IAsyncRequestHandler<TRequest, Unit> _requestHandler; | |
private readonly IValidationHandler<TRequest> _validationHandler; | |
public RequestValidationDecorator(IAsyncRequestHandler<TRequest, Unit> requestHandler, IValidationHandler<TRequest> validationHandler) | |
{ | |
_requestHandler = requestHandler; | |
_validationHandler = validationHandler; | |
} | |
public async Task<Unit> Handle(TRequest message) | |
{ | |
_validationHandler.Validate(message); | |
return await _requestHandler.Handle(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment