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

Опубликовано: 14 Октябрь 2024
на канале: Amichai Mantinband
39,994
1k

Become a Patreon & get the source code:   / amantinband  

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 ⭐:
https://github.com/FluentValidation/F...

#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