Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.