Similar Posts

Leave a Reply

Your email address will not be published.

10 Comments

  1. Also you employ inconsistent syntax in the validation handler. Either use Any() in both cases or in none.
    Also why to check for the number of underlying validators in the first place? Just don’t.
    If you really want to – memorize them in the ctor and throw an exception if none were passed, that’s clearly a composition root / design-time mistake.

  2. Hi Mukesh, nice article and very well explained. But why we should use MediatR pipeline behaviour because this feature is already provided in .net core and it validate the incoming request model before hitting our controller action method even before MediatR pipeline. And if we use FluentValidation.AspNetCore package than it will do the same thing, I think that’s why you mentioned to install FluentValidation.DependencyInjectionExtensions, so it can hit the action method and can pass through MediatR pipeline behaviour. So, to conclude, I think this approach would make more sense if we want to validate our incoming request model as well as domain model also. Please correct me if I am wrong?