While looking for something totally different the other day, I have stumbled upon two libraries for doing Fluent Validation in .NET.
The concept seems interesting since so far I am doing my validations using the usual conditional and branching statements (if, else, case, etc).
In particularly, it makes relatively easy to chain some conditions which could result in some cases in shorter code for complex conditions, and to embed several error messages for each violations in the same object.
That said, isn’t it also making the code look more verbose than C# usually is, a bit like T-SQL can be at times… and doesn’t this cause the code to have an inconsistent look and feel?
In short, what do you think of Fluent Validation and if you like it, which library have you found to be the best for it? So far, I have looking at http://tnvalidate.codeplex.com/ and http://fluentvalidation.codeplex.com/ which seem more or less equivalent at the first glance…
Thanks.
I’m using my own validation library that I’ve published here.
The difference with the two that you suggested is that the validations are put into separate validation classes. You can create and forget the validation classes, they are automatically discovered by the validation library.
It’s also easy to add support for localizations using your very own favorite localization libray (such as a string table)
And to configure:
The actual validation is done like this: