Validation using MediatR's Pipeline Behaviors and FluentValidation | Clean .NET Core

preview_player
Показать описание

Hello everybody I'm Nick and in this ASP.NET Core tutorial I will show you how you can use MediatR's Pipeline Behavior feature to add domain level validation in your API in a very clean way. We will add it using a very intuitive way, without mixing it with our happy path logic in our main IRequestHandler. I will also explain how exactly Pipeline Behaviors work and why they are a perfect fit for this piece of functionality. The validation logic will use FluentValidation.

Don't forget to comment, like and subscribe :)

Social Media:

#aspnetcore #mediatr #tutorial
Рекомендации по теме
Комментарии
Автор

Thanks for the great video Nick. In the ValidationBehavior class, you mentioned that you were just throwing the new ValidationException(failures) exception for demonstration simplicity and that you would want to use an error handler pipeline rather than exception in production code. Can you point me to an example of the error handler pipeline?

davidadler
Автор

Thanks for your dedication to what you do. Will you consider using a zoom in tool whenever you start coding 🙂

RamiNassarPlus
Автор

@13:53 "...& Keep in mind this is domain-level validation!.."

Been wondering how to do this simply with fluent validator for a while & it turns out Mediatr was the this missing link all along.

Great point + easy to miss for those used to only this endpoint-level/DTO validator usage which is far more common in experience

toastybowl
Автор

Great video Nick!

In a future video it would be really nice to see how to properly apply testing when using MediatR and the CQRS pattern.

jamesbarlow
Автор

I love these videos. I'm learning so much about modern patterns and practices after a long break from professional programming. Thank you! I tried to adapt the pattern in this video so as not to throw a validation exception (as you recommended yourself) but I found it to be very difficult and didn't find any good examples on the internet. Is there a pattern you recommend? Do you still believe it's important not to throw a costly ValidationException to signal an invalid command?

benjamincharlton
Автор

Thanks for the demostration, is a exelent form to initialize with MediatR and CQRS on create API services

emmanuelcaamal
Автор

Brilliant work, your videos are precious and clear. Like it!

gerappa
Автор

Nice. Looking forward to implementing notifications in the Meditr pattern and using it in project about success or failure operation.

shreyasjejurkar
Автор

Awesome video. Well-explained with perfect pace!

TBPer
Автор

If you have a playlist, please add it you your video descriptions. It's always hard for me to find a playlist which video is in it

SajadJalilian
Автор

Thanks for the great content and videos, by the way... how to do unit tests for this pipeline validation behavior?

clarke
Автор

Amazing video, very clearly. Thanks for sharing

leandrowitzke
Автор

Just one question, does adding this transient service of pipeline behavior cause significant load w.r.t to performance or it more or less same? or to be simple does this overall process of validation impact performance of the microservice?

SURBH
Автор

As you mentioned Domain level validation; would you implement a validator for say "User does not exist" during a login process? If not, how would you implement this at the Handler level?

davidprice
Автор

At around 10:45: Instead of throwing exceptions from validation, return a Result<TResponse>
Then in the pipeline translate it to a BadRequest, etc...
Which pipeline? An action filter in the API I guess?

Fred-yqfs
Автор

Thanks for the video.
How does multiple behaviours share data in MediatR?

ankitnagpal
Автор

Hey Nick, Thanks for the great video.
10:45 I am unable to implement this. I have searched the internet and everyone is throwing exceptions.
Could you please share an example of this.
Thanks in advance.

HarjinderSingh-dfbs
Автор

And is it a good thing to let the raw request data to hit the action method? Every developer in the team should be aware of this behavior, otherwise one could think that the request data has already been validated.

temp
Автор

Ok, let say that I'm not going to use Exception Handler, what can be a real alternative in order to say something went wrong?

bonaoenchelcha
Автор

Great video. Thanks for the explanation. What tool do you use to draw on the screen like that?

LemmensSteven