Download - Fluent validation
![Page 1: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/1.jpg)
FLUENT VALIDATION
SARAVANAN SUBBURAYALJEEVAN TECHNOLOGIES
07-MAR-2013
![Page 2: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/2.jpg)
Agenda
• Fluent Validation – Who am I?• Validator Creation• Built in Validators• Validator customizations• Localization support• Benefits• Conclusion
![Page 3: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/3.jpg)
Fluent Validation – Who am I?
• Open source Validation library for .net• Uses Fluent interfaces and lambda expressions for
building validation rules• Source available in GitHub• Available as Nu-get packages– FluentValidation– FluentValidation.MVC3– FluentValidation.MVC4
• Signed binaries are also available
![Page 4: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/4.jpg)
Validator Creation
• Validator class : AbstractValidator<>• Validation Result– IsValid– Errors
• Chaining Validators• Throwing Exceptions• Validators for Complex properties• Validators for Collections• Rule Sets
![Page 5: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/5.jpg)
Built in Validators
• NotNull Validator• NotEmpty Validator• NotEqual Validator• Equal Validator• Length Validator• Less Than Validator
![Page 6: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/6.jpg)
Built in Validators (contd.,)
• Less Than Or Equal Validator• Greater Than Validator• GreaterThan Or Equal Validator• Predicate Validator (aka Must)• RegEx Validator• Email Validator
![Page 7: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/7.jpg)
Validator customizations
• Overriding the default error message– .WithMessage(“…”)
• Overriding the Default Property Name– .WithName(“Family name")
• Specifying a condition (When/Unless)– .When(Student.Age > 30)
• Cascading– .Cascade(CascadeMode.StopOnFirstFailure)
![Page 8: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/8.jpg)
Localization support
• It supports the following languages:– English– French– German– Dutch– Spanish– Portuguese
![Page 9: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/9.jpg)
Localization support (contd.,)
• Using Custom Resource Provider
• Messages must be public and static
![Page 10: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/10.jpg)
Localization support (contd.,)
• Resource names that can be customizedemail_error equal_error exact_length_error exclusivebetween_errorgreaterthan_error greaterthanorequal_errorinclusivebetween_error length_errorlessthan_error lessthanorequal_errornotempty_error notequal_errornotnull_error predicate_errorregex_error
![Page 11: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/11.jpg)
Benefits
• It separates validation from the Model• Unit testing is easier• Can perform different conditional validations
on different properties• Re-usability• No need for annotations (which make the
code looks clumsy)
![Page 12: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/12.jpg)
DEMO
![Page 13: Fluent validation](https://reader034.vdocuments.us/reader034/viewer/2022042501/5577c5d0d8b42a1c068b540c/html5/thumbnails/13.jpg)
If (!Questions){ “THANK YOU!!!”;}