Fluent Validation vs. Data Annotations

.Netasp.net MvcData AnnotationsFluentvalidation

.Net Problem Overview


What are the operative differences between these two validation packages when used for ASP.NET MVC validatation? They seem to have similar objects, all the way to their object names. Is one related to another? What are their differences? In what way do these differences denote different use cases?

.Net Solutions


Solution 1 - .Net

I prefer Fluent Validation:

  1. It gives me far better control of my validation rules
  2. Doing conditional validation on different properties is so much easier compared to Data Annotations
  3. It separates the validation from my view models
  4. Unit testing is far easier compared to Data Annotations
  5. It has excellent client side validation support for most standard validation rules

Solution 2 - .Net

I clearly prefer Data Annotations because ...

  1. all validation rules can be configured in one place in code (within the model metadata class) and don't need to be repeated anywhere else.
  2. there is excellent support for client side validation (again – without repetition of validation rules!) when using Data Annotation attributes.
  3. Data Annotation attributes can be tested to ensure they're there.
  4. there are nice additional validation attributes created by the community (e.g. Data Annotations Extensions).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSiberianGuyView Question on Stackoverflow
Solution 1 - .NetDarin DimitrovView Answer on Stackoverflow
Solution 2 - .NetMarius SchulzView Answer on Stackoverflow