Your SlideShare is downloading. ×
  • Like
Fluent validation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Fluent validation

  • 1,383 views
Published

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

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,383
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
13
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

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

Transcript

  • 1. FLUENT VALIDATION SARAVANAN SUBBURAYAL JEEVAN TECHNOLOGIES 07-MAR-2013
  • 2. Agenda• Fluent Validation – Who am I?• Validator Creation• Built in Validators• Validator customizations• Localization support• Benefits• Conclusion
  • 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. Validator Creation• Validator class : AbstractValidator<>• Validation Result – IsValid – Errors• Chaining Validators• Throwing Exceptions• Validators for Complex properties• Validators for Collections• Rule Sets
  • 5. Built in Validators• NotNull Validator• NotEmpty Validator• NotEqual Validator• Equal Validator• Length Validator• Less Than Validator
  • 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. 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. Localization support• It supports the following languages: – English – French – German – Dutch – Spanish – Portuguese
  • 9. Localization support (contd.,)• Using Custom Resource Provider• Messages must be public and static
  • 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. 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. DEMO
  • 13. If (!Questions){ “THANK YOU!!!”;}