Model Validation | Validation Attributes vs. FluentValidation | .NET 6

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

In this video, we'll learn how to use the built-in validation attributes for model validation and also how we can create custom validation attributes to match our needs.

We'll then cover some of the reasons why we might prefer using the FluentValidation library instead.

In the FluentValidation library, we'll cover the following:
0. FluentValidation vs FluentValidation.AspNetCore
1. FluentValidation built-in validators
2. FluentValidation custom validators
3. FluentValidation and Dependency Injection
4. FluentValidation & nested objects
5. FluentValidation & including rules from other validators
6. FluentValidation's built-in Message Placeholders
7. FluentValidation & Custom Placeholders

Give FluentValidation a ⭐:

#dotnet

00:00. The project we'll be using as an example
02:15. Built-in Validation Attributes
03:05. Returning a ValidationProblem when the ModelState isn't valid
04:00. ApiController Attribute - Automatic 400 responses & Automatic binding
05:00. Custom Validation Attributes
06:14. Custom Validation Attributes: Custom Error Message
07:12. Validation Attributes vs. FluentValidation
08:31. Adding the FluentValidation Nuget package
08:41. Implementing our first Validator
09:38. Registering the Validator using the IValidator interface
10:06. FluentValidation Manual Validation
11:52. Adding the FluentValidation.AspNetCore Nuget package
12:06. Registering the Validator using the AddValidatorsFromAssemblyContaining extension method
12:56. FluentValidation Automatic Validation (AddFluentValidation extension method)
13:32. FluentValidation Automatic Validation disclaimer
14:20. FluentValidation Built-in validators (RuleFor, Must, NotNull, NotEmpty, CreditCard, Match)
15:05. Validators & Dependency Injection
16:05. FluentValidation RuleForEach & WithMessage
17:11. FluentValidation Custom Validator (IRuleBuilderOptions, IRuleBuilder)
19:55. Custom Validator & Custom error message
20:20. Built-in Placeholders (PropertyName, PropertyValue)
21:06. Custom Placeholders (ValidationContext, MessageFormatter)
22:33. Updating the CreateBreakfastRequest to have a nested object
23:50. Implementing the BreakfastDetailsValidator
23:50. Implementing the BreakfastDetailsValidator
24:40. Setting an external validator on nested objects (SetValidator)
25:20. Splitting rules across multiple files (Include)
26:51. Next video sneak peek
Рекомендации по теме
Комментарии
Автор

Love your videos! Every time you say "Yes" whenever the copilot autofill's syntax is really satisfying. Co-pilot is really great

joshmeyers
Автор

Such a great introduction to the FluentValidation library. I loved that you showed that DI is supported inside of validators. Great job!

MilanJovanovicTech
Автор

you are the best .net technology teacher I have ever seen.

DanielTames
Автор

Thank you dear for your detailed, quick, and straightforward demonstration.

faisalalhoqani
Автор

I've been using FluentValidation for some time now and was stunned by what I saw you doing with this custom validator. Great video, thanks !

iliyan-kulishev
Автор

Great video. Been diving into a dotnet project at work and needed some refreshers over this.

DarkMetroid
Автор

Thanks for this great introduction into the FluentValidation library.

wvanlosser
Автор

Great overview of FluentValidation package, I realy like last parts about custom validators.

Thanks!

branislavpetrovic
Автор

This video has everything I was looking for, incredible, thank you!

haskell
Автор

Bro your channel is small but you are making some of the best .NET 6 content already. Keep up the good work.

opachshwee
Автор

Hi, great video as always. But I have doubts about the rules for the creation of Breakfast. I'm using a "DDD approach", so Breakfast is an Entity that has a static method "Create()" that works as Factory Method. In your example, you put the "sunrise" rules inside the DateTimeValidators and not inside the "Create()" method of Breakfast class. Is this a good approach? I have to put all the creation rules inside my “BuberBreakfast.Contracts” project and Validators or should I put the creation rules inside the Entity Breakfast?

In short, the creation logic of an entity must be put inside our contracts or inside the Entities?

Thanks!

evilTano
Автор

Great pacing and information, keep up the great work. My only complaint is I cant get videos fast enough! :D

silvertek
Автор

Hey Amichai :) I have been subscribed to your channel since your first video came out and I though it was about time to leave a comment. I really enjoy watching your videos. They are informative and at the same time fun to watch (at least for someone interested in coding and software archtiecture). At work we already use a lot of the technologies and patterns you introduced in your last videos. Nevertheless, I still learned one or two new things or got a different perspective on things. Thank you for that.

danielschmitt
Автор

I liked this "Yes" to the copilot autofill :D. I didn't get the idea behind the IAssemblyMarker, can you please elaborate more?

khaledsaleh
Автор

Nice video! Could you make more detailed video about Attributes and how to use them for validation? Also making Custome Attribute validators?

keyable
Автор

Great video! Nice structured and explained.
What extension or customization are you using for your terminal? The color state of the branch and path looks gorgeous.

kgofawesome
Автор

I love your videos, it's very straightforward. Can you share your setup when recording (VScode, screen recorder, etc) in the future?

fakhrulhilal
Автор

Fantastic playlist. Can this use for domain entity validation ?

akalankagajasinghe
Автор

what is the name of the screen recorder you're using to do marks during recording ?

androidsavior
Автор

Thanks for the great content, it really inspires me to improve myself to become a better developer. Your are doing great, keep going 👍

dicusardenis