jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.02k stars 1.16k forks source link

Check all requests have handlers #845

Closed Hunglmc closed 1 year ago

Hunglmc commented 1 year ago

I have function below:

public sealed class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    private readonly IEnumerable<IValidator<TRequest>> _validators;

    public ValidationBehaviour(IEnumerable<IValidator<TRequest>> validators)
    {
        _validators = validators;
    }

    public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
    {
        if (_validators.Any())
        {
            var context = new ValidationContext<TRequest>(request);

            var validationResults = await Task.WhenAll(
                _validators.Select(v =>
                    v.ValidateAsync(context, cancellationToken)));

            var failures = validationResults
                .Where(r => r.Errors.Any())
                .SelectMany(r => r.Errors)
                .ToList();

            if (failures.Any())
                throw new ValidationException(failures);
        }
        return await next();
    }
}

in version Mediart 9.0 it working nice.But when i update to version 11.0 i see erros

 Severity   Code    Description Project File        'ValidationBehaviour<TRequest, TResponse>' does not implement interface member 'IPipelineBehavior<TRequest, TResponse>.Handle(TRequest, RequestHandlerDelegate<TResponse>, CancellationToken)'  .

Please tell me about how to fix this. Thank you so much team.

jbogard commented 1 year ago

See the release notes:

https://github.com/jbogard/MediatR/releases/tag/v12.0.0

And upgrade guide:

https://github.com/jbogard/MediatR/wiki/Migration-Guide-11.x-to-12.0

Check the other upgrade guides to see if anything else needs to be applied from version 9.0