Get the source code for this video for FREE → the-dotnet-weekly.ck.page/cqrs-validation Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@F2H16 Жыл бұрын
Hi Milan, is it possible to get the access to the source code?
@rakkarajput2 жыл бұрын
Concept clear now, fully explained Thanks Buddy 🥳🥳🥳keep it up
@MilanJovanovicTech2 жыл бұрын
Awesome, I'm glad all the pieces made sense in the end.
@roefski2 жыл бұрын
Hi Milan, awesome video as always 🙂. Any chance you'll be doing authorization/authentication with a clean architecture setup?
@MilanJovanovicTech2 жыл бұрын
It's going to happen for sure!
@flobuilds2 жыл бұрын
@@MilanJovanovicTech will you build on top of identity server and implement a decent user management?
@ayanesuarezromero42224 ай бұрын
Very nice video. It helps me make my validation result much cleaner and simpler. Thank you!
@MilanJovanovicTech4 ай бұрын
Glad it was helpful!
@bookuha2 жыл бұрын
Yeeee thank you Milan!
@MilanJovanovicTech2 жыл бұрын
You're welcome!
@ibrahimzaky30563 ай бұрын
this video help me to solve problem ... thank you man
@MilanJovanovicTech3 ай бұрын
You're most welcome!
@AboutCleanCode2 жыл бұрын
I see your design growing and growing - in these sense of number of classes involved - with the decoupled design you have chosen. would be interesting to compare it to an alternative, more pragmatic design where input validation just happens in the controller and the application logic is just called via API from there as well 😉
@MilanJovanovicTech2 жыл бұрын
It would surely make for an interesting comparison.
@elpe21 Жыл бұрын
Yeah, the validation done in this video can be done with DataAnnotations. I'm in the process of googling opinions on DataAnnotations with some class-validations vs FluentValidations.
@kirillhorn31862 жыл бұрын
Your video is awesome as always!!!
@MilanJovanovicTech2 жыл бұрын
Thank you very much!
@davidpccode Жыл бұрын
Hello great content. Thank you very much. I have read and seen a lot of content about command validation but I still can't find a reason that justifies so much over-engineering and so much complexity. I can achieve the same thing by injecting a class that performs all the validations with less than half the effort and with the same result. what am i missing? Thanks in advance 👍
@MilanJovanovicTech Жыл бұрын
Nope, you got it right
@omar-fathy019 ай бұрын
Awesome ❤ do you have a vertical slice architecture lesson?
@MilanJovanovicTech9 ай бұрын
kzbin.info/www/bejne/o6TNn5mamql2o9E
@sphrtehrani Жыл бұрын
Hi Milan. Great videos. Now we are validating our entities twice. Once in pipeline behaviour with fluent validation and once in our value objects. Isn't it code duplication.
@MilanJovanovicTech Жыл бұрын
Different kind of validation. It's a tradeoff I can live with.
@dirceusjr Жыл бұрын
The validation result creation could be simplified by creating an interface TResult with a SetError() method. With that interface on your result type, you just need to call new TResult() and then the SetError() method in the ValidationBehaviour.
@MilanJovanovicTech Жыл бұрын
That would've been interesting
@davittonoyan6537 Жыл бұрын
Please can you show it in the example how to do it?
@rakkarajput2 жыл бұрын
Please create a video on micro services and micro frontend
@MilanJovanovicTech2 жыл бұрын
I'll consider it
@aamirali8114 Жыл бұрын
i guess youtube was listening meeting between me and my manager who was discussing yo implement CQRS and Fluent Api
@MilanJovanovicTech Жыл бұрын
There's also this version, which is slightly different: kzbin.info/www/bejne/hZm0cmeGecmjZrM
@codearabawy Жыл бұрын
Thanks for the video! I'm not clear about a point here. How can you pass a list of validators to specific handler?
@MilanJovanovicTech Жыл бұрын
If you create multiple AbstractValidator for the same command, they'll be passed in to the behavior
@pazzuto Жыл бұрын
Great video! One comment about the HandleError method... shouldn't the wildcard return a 505 instead of a 404?
@MilanJovanovicTech Жыл бұрын
You can pick what you think is best for your API
@zikkrype2 жыл бұрын
Nice. But there are plenty of those over the internet with such fluent validation usage in mediatr pipeline. But none of those considered that AbstractValidator has also async overload. And your validator may have Validate or ValidateAsync implemented or even both. And in this case ValidateAsync would be ignored. Release Part II with such improvement. And I guess you will be the first one
@MilanJovanovicTech2 жыл бұрын
I don't like to place async validation in the pipeline. This would probably be data validations or something similar. I prefer to place these in the application layer directly (handlers)
@zikkrype2 жыл бұрын
@@MilanJovanovicTech like it or not, but here validation is flawed. I don't think that it's the best idea to write something like "please use Validate over ValidateAsync when writing validators"
@elpe21 Жыл бұрын
@@MilanJovanovicTech I agree with @Nazarii. You were already made a video about Email address being unique where you have to access a database which is perfect example. Lastly, I'm not sure if I'm fan or not of Fluent Validations. Too often you have to write own functions anyway
@fieryscorpion2 жыл бұрын
Can you please make a video on logging using Serilog in your setup?
@MilanJovanovicTech2 жыл бұрын
Sure, Serilog is a great library
@thomaswoods13657 ай бұрын
Great video Milan, could you possibly show how this could be achieved using FastEndpoints implementation? How would someone setup a base class like you did at 15:21 with HandleFailure in a FastEndpoints solution?
@MilanJovanovicTech7 ай бұрын
I'll see what I can do 😁
@thomaswoods13657 ай бұрын
@@MilanJovanovicTech the solution for validation in FastEndpoints incorporates FluentValidation. I'll follow their guidance on that. Take a look. If you have any improvements I'd love to see it. Thank you Milan!
@justhobbes46822 жыл бұрын
Didn't you approach this using value objects that encapsulated this validation logic? When would you use fluent validation over value objects?
@MilanJovanovicTech2 жыл бұрын
I use this approach for Input validation. Simple stuff like not null, not empty. For more complex stuff, I like to keep it in the Application/Domain layers.
@justhobbes46822 жыл бұрын
Does that mean you allow nulls or empty strings in your domain layer? And if not, isn’t that duplication of validation logic? Both sound a bit iffy! What do you think?
@arjavdave10152 жыл бұрын
@@justhobbes4682 I am also a bit confused here. If we are going for rich domain models then I don't see a reason to have fluent validation.
@stjepankarin2 жыл бұрын
You need to understand the difference between input validation and business validation. Take an email address field for ex. Input validation will ensure that, given we want this field to be mandatory, it is not null/empty and it is a valid email address, conforming to the current spec. Business validation on the other hand might ensure that only specific set of email addresses are valid like from specific domain, or that some unique address within that application are allowed, etc. It is preferred to keep these separate as they by nature evolve for a different reasons. Also, input validation is always placed in most outer layer, while business is part of application or in some cases core domain. This will ensure neither empty strings nor nulls (if that is what we want) can get it to you domain layer. I hope this helps with clarification!
@viktorasmickunas2527 Жыл бұрын
Is there a specific reason why you create Result/Error, etc. classes yourself? There is a FluentResults package that seems to provide a reasonable implementation for this. Have you tried it?
@MilanJovanovicTech Жыл бұрын
I like to customize it per the project needs. I started using this a while ago. I wasn't aware of FluentResults at the time, so I just stuck with mine. I'll see what it offers past the basics.
@SalmanShafiq-y3q7 ай бұрын
Fluid Milan ❤ What is IValidationResult here? Does come from FluentValidation?
@MilanJovanovicTech7 ай бұрын
It comes from FluentValidation
@abderrazakhenka3903 Жыл бұрын
Hi Milan, thanks for sharing knowledge, I am watching your videos, and I like what you do. I have a question, are you using same code of CreateValidationResult(Error[] errors){...} in your production code? or this is just a simple example.
@MilanJovanovicTech Жыл бұрын
More or less, yes. Do you feel like something is missing?
@abderrazakhenka3903 Жыл бұрын
@@MilanJovanovicTech No, it is fine, just I am concerned about the performance in a high load system.
@hakimedusti4 ай бұрын
Thanks
@MilanJovanovicTech4 ай бұрын
No problem!
@VitaliiShmidt-UA Жыл бұрын
Hi Milan. Thanks a lot for sharing such a nice and helpful information. Can you please share the source code of this project?
@MilanJovanovicTech Жыл бұрын
Send me an email: milan@milanjovanovic.tech
@mustafahaider91153 ай бұрын
the only thing that seems to be strange for me is you only register the service of the validationPipeLine you didn't actually use it as a mediatr middleware so how did it get used, it is so strange to me I use the same technique but I use the addBehavior but anyway thank you for all the efforts
@MilanJovanovicTech3 ай бұрын
That's just one way to do it
@SalmanShafiq-y3q7 ай бұрын
Could you please make video on Validation Pipeline Behaviour With Minimal API?
@MilanJovanovicTech7 ай бұрын
It's the same, no?
@r75shell Жыл бұрын
How do you handle class fields binding errors? like if command has integer fields, and someone passed "one" which is not a number. Isn't it converted into 0 by default? And, therefore going through all code, because we don't check ModelState.IsValid.
@MilanJovanovicTech Жыл бұрын
You can add a NotDefault check with FluentValidation
@ИванИванов-о8я9с Жыл бұрын
Hi, how to return FluentValidation.Results.ValidationResult object instead of your custom validation result?
@MilanJovanovicTech Жыл бұрын
Replace it in the entire pipeline
@Omar.bin.khattab11 ай бұрын
thanks for your time but keep it simple as possible
@MilanJovanovicTech11 ай бұрын
What do you mean?
@masoudmotlagh63848 ай бұрын
Can we reuse this validator in blazor client? is it clean to inject or use command validators in client?
@MilanJovanovicTech8 ай бұрын
Not sure how it would work in Blazor, but you probably can
@masoudmotlagh63848 ай бұрын
@@MilanJovanovicTech we can use the pipeline validator in client project but I was thinking if that is a good and clean way to mention "command" in blazor client project and use like this: ... We can add another validator for viewModels or dtos with same validation rules but then we have to maintain two validators for one scenario. so, what do yo think is the best way to reuse validators? or maybe we should just consider sharing the rules between validators?
@YoussefAbdullah-s6y8 ай бұрын
could you provide the code for result class and result class ?
Hello, can you show your "Result" and "Error" classes?
@MilanJovanovicTech Жыл бұрын
You can see an example here: github.com/m-jovanovic/rally-simulator
@timur28875 ай бұрын
Thank you!
@MilanJovanovicTech5 ай бұрын
You're welcome!
@empireofhearts Жыл бұрын
is there repo for the project you uses in these videos? it would be really helpful to have all in one place to go thorugh. @milan
@MilanJovanovicTech Жыл бұрын
I share it on my Patreon
@harryh212 Жыл бұрын
Is it possible to have as pipeline like this on a crud style service?
@MilanJovanovicTech Жыл бұрын
With the decorator pattern?
@awmy31092 жыл бұрын
I honestly don't know why C# programmers keep pushing this MediatR package. I really don't see it's usefulness. Simple methods or classes that take required interfaces as arguements is a simple, straight forward solution. If you like, you can make them static and not need to instantiate anything to use them.
@MilanJovanovicTech2 жыл бұрын
It's a powerful package when you look beyond method calls. PipelineBehaviors is my favorite feature. Each handler class is simple, and ideally does one thing, which promotes single responsibility.
@pwn2own232 жыл бұрын
Nice video. How do you keep the open api spec (swagger) and the fluent validation rules in sync in the daily life? Any tips?
@MilanJovanovicTech2 жыл бұрын
I don't think about that, to be honest
@pwn2own232 жыл бұрын
@@MilanJovanovicTech hehe, ok. then you never had team-external consumers 🤪
@PelFox Жыл бұрын
@@pwn2own23 there is a nuget for that called MicroElements.Swashbuckle.FluentValidation which adds all your FluentValidation validators to the swagger schema.
@ravindranaths513 Жыл бұрын
Hi Milan, Why IDomainEventHandler is given in Application layer; instead of Domain layer?
@MilanJovanovicTech Жыл бұрын
That's what makes sense to me
@TheEmqe3 ай бұрын
the question is how can we show the errors on bootstrap modal ? and my project not API .net core mvc
@MilanJovanovicTech3 ай бұрын
Return them through the API response
@syedjunaid78469 ай бұрын
Alternatively, could we just throw an exception during validation, which will encompass all our errors with mabye an 'errors' property, and handle that exception in an exception handling middleware in our presentation layer?
@MilanJovanovicTech9 ай бұрын
Yes
@verbroez712Ай бұрын
Exceptions slow down applications
@norelayaien98882 жыл бұрын
I did not realize that in class Result what is it
@MilanJovanovicTech2 жыл бұрын
What exactly?
@giovannis65068 ай бұрын
For some reason my ValidationPipelineBehavior is not firing off. It appears that "where TResponse : Result" is not found by Mediatr. Any advice assuming I followed your tutorial?
@MilanJovanovicTech8 ай бұрын
Which .NET version are you using?
@abhikarne Жыл бұрын
hey man, you do not show Error Class :(
@MilanJovanovicTech Жыл бұрын
Just a simple class with Code and Description properties
@singernooneheard6967 Жыл бұрын
Do we need the problem detail object if we use the result pattern (eg. languageExtcore)
@MilanJovanovicTech Жыл бұрын
As long as you return a standardized response from the API, I would consider it alright
@CommentingOnTheFreakshow8 күн бұрын
OR, you could just create simple object with functions that perform your validation where you pass in the data object and just do your validation checks directly on the model object and save yourself all that needless abstraction which is not free in terms of application performance!
@MilanJovanovicTech7 күн бұрын
We could
@Tamer_Ali2 жыл бұрын
Hi Milan, thanks for your video are you going to talk about CQRS and Minimal API in Clean Architecture?
@MilanJovanovicTech2 жыл бұрын
CQRS was the previous video. And I'm planning Minimal API soon :)
@DanKac1824 ай бұрын
Does it still make sense to use the binding validation on the request body object that .net validate as default?
@MilanJovanovicTech4 ай бұрын
Yes, but if you're using [ApiController] or minimal APIs those will be applied by default
@DanKac1824 ай бұрын
@@MilanJovanovicTech so both validations would be applied? aren't they doing kind the same in the end of the day?
@pablofonseca88676 ай бұрын
Seems like everyone is addicted to DDD pattern because they want to be popular, code structure is complicated to read and understand as F, but they apply it to be more understandable lol
@MilanJovanovicTech6 ай бұрын
There was basically zero "DDD patterns" in this video. What are you talking about?
@muhamotto208410 ай бұрын
man you are complicating things too much!! you are using the fluentValidation library, so just use it instead of extending it !
@MilanJovanovicTech10 ай бұрын
What are you talking about? With the pipeline in place, I can just create validators and they'll be applied automatically
@SalmanShafiq-y3q7 ай бұрын
Validation Pipeline not call in mediator Pipeline bahaviour. Initially I added this pipeline like this way. services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly(), includeInternalTypes: true); services.AddMediatR(cfg => { cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); cfg.AddOpenBehavior(typeof(RequestLoggingBehaviour)); cfg.AddOpenBehavior(typeof(ValidationPipelineBehaviour)); }); after not working then i did like this way. services.AddScoped(typeof(IPipelineBehavior), typeof(ValidationPipelineBehaviour));
@SalmanShafiq-y3q7 ай бұрын
I am using .NET 8
@SalmanShafiq-y3q7 ай бұрын
internal sealed class ValidationPipelineBehaviour : IPipelineBehavior where TRequest : notnull where TResponse : Result here, after changed generic constraint IRequest to notnull, this pipeline behaviour get called.😲