FLUENT VALIDATION      SARAVANAN SUBBURAYAL       JEEVAN TECHNOLOGIES               07-MAR-2013
Agenda•   Fluent Validation – Who am I?•   Validator Creation•   Built in Validators•   Validator customizations•   Locali...
Fluent Validation – Who am I?• Open source Validation library for .net• Uses Fluent interfaces and lambda expressions  for...
Validator Creation• Validator class : AbstractValidator<>• Validation Result    – IsValid    – Errors•   Chaining Validato...
Built in Validators•   NotNull Validator•   NotEmpty Validator•   NotEqual Validator•   Equal Validator•   Length Validato...
Built in Validators (contd.,)•   Less Than Or Equal Validator•   Greater Than Validator•   GreaterThan Or Equal Validator•...
Validator customizations• Overriding the default error message  – .WithMessage(“…”)• Overriding the Default Property Name ...
Localization support• It supports the following languages:  – English  – French  – German  – Dutch  – Spanish  – Portuguese
Localization support (contd.,)• Using Custom Resource Provider• Messages must be public and static
Localization support (contd.,)• Resource names that can be customized  email_error              equal_error  exact_length_...
Benefits• It separates validation from the Model• Unit testing is easier• Can perform different conditional validations  o...
DEMO
If (!Questions){   “THANK YOU!!!”;}
Upcoming SlideShare
Loading in …5
×

Fluent validation

2,019 views
1,803 views

Published on

Fluent Validation is a validation library for .NET. It uses a fluent interface and lambda expressions for building validation rules for your business objects.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,019
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • RuleFor(customer =&gt; customer.Surname).NotNull().WithMessage(&quot;Please ensure that you have entered your Surname&quot;);RuleFor(customer =&gt; customer.Surname).NotNull().WithName(&quot;Last name&quot;);RuleFor(customer =&gt; customer.CustomerDiscount).GreaterThan(0).When(customer =&gt; customer.IsPreferredCustomer);RuleFor(x =&gt; x.Surname).Cascade(CascadeMode.StopOnFirstFailure).NotNull().NotEqual(&quot;foo&quot;);
  • Fluent validation

    1. 1. FLUENT VALIDATION SARAVANAN SUBBURAYAL JEEVAN TECHNOLOGIES 07-MAR-2013
    2. 2. Agenda• Fluent Validation – Who am I?• Validator Creation• Built in Validators• Validator customizations• Localization support• Benefits• Conclusion
    3. 3. 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
    4. 4. Validator Creation• Validator class : AbstractValidator<>• Validation Result – IsValid – Errors• Chaining Validators• Throwing Exceptions• Validators for Complex properties• Validators for Collections• Rule Sets
    5. 5. Built in Validators• NotNull Validator• NotEmpty Validator• NotEqual Validator• Equal Validator• Length Validator• Less Than Validator
    6. 6. Built in Validators (contd.,)• Less Than Or Equal Validator• Greater Than Validator• GreaterThan Or Equal Validator• Predicate Validator (aka Must)• RegEx Validator• Email Validator
    7. 7. 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)
    8. 8. Localization support• It supports the following languages: – English – French – German – Dutch – Spanish – Portuguese
    9. 9. Localization support (contd.,)• Using Custom Resource Provider• Messages must be public and static
    10. 10. Localization support (contd.,)• Resource names that can be customized email_error equal_error exact_length_error exclusivebetween_error greaterthan_error greaterthanorequal_error inclusivebetween_error length_error lessthan_error lessthanorequal_error notempty_error notequal_error notnull_error predicate_error regex_error
    11. 11. 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)
    12. 12. DEMO
    13. 13. If (!Questions){ “THANK YOU!!!”;}

    ×