Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active April 18, 2016 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/058ff3abb049878736d50962dc529267 to your computer and use it in GitHub Desktop.
Save dcomartin/058ff3abb049878736d50962dc529267 to your computer and use it in GitHub Desktop.
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