7

I am trying to choose one of the validation frameworks for a major application, and while both options seem enticing, I was wondering whether there are any specific pros and cons I should be aware of before committing to one or the other.

Steven
  • 166,672
  • 24
  • 332
  • 435
mr.sverrir
  • 414
  • 4
  • 12
  • Web or desktop? Are u using other entlib blocks? Would you please specify the architecture? – boj Apr 15 '09 at 14:16
  • It is for a web application. I might use other entlib blocks, such as security and logging, as that will be required in the application. I won't use Unity though, as that bit will be handled by Spring.NET – mr.sverrir Apr 15 '09 at 16:02
  • 1
    I've no experience with Spring.NET but I'm a big fan of EntLib blocks. You should read http://weblogs.asp.net/ricardoperes/archive/2009/03/11/asp-net-validation-with-the-enterprise-library-validation-block.aspx and http://www.davidhayden.com/blog/dave/archive/2007/02/28/PropertyProx – boj Apr 16 '09 at 15:12
  • Thanks a lot! I will definitely consider EntLib. – mr.sverrir Apr 17 '09 at 07:30

2 Answers2

8

Validation with attributes is not best solution in my view. Firstly you have to reference infrastructure in domain model. Secondly you don't have any chance to add validation to compiled classes. Lastly you can't validate complex logic with attributes and you have to make Validate method to entity and that just seems awkward.

In my opinion validation should be separated to different object. For example IValidator where you could define validation as rules. Using framework like xVal helps to do validation in presentation layer with JavaScript.

You may want to look for xVal and FluentValidation for .NET. NHibernate Validator 1.2 alpha has fluent syntax as well and it is integrated with xVal (not sure about alpha, but 1.0 should be).

Enterprise Validation Block has few negative sides as well. My entity's properties ended up having 3 rows of attributes and made readability worse. Trying to add validation with AND or OR operators is quite painful too.

Marek Tihkan
  • 1,914
  • 13
  • 11
  • 1
    Validation Application Block doesn't have to be used with attributes. It contains a configuration based validation approach. Read this article: http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=46 – Steven Feb 09 '10 at 11:15
  • 1
    While I prefer configuration based validation over attribute based configuration for the same reason as Marek describes, VAB 5.0 allows you define validations using the buddy class technique that was introduced by DataAnnotations. – Steven Aug 31 '10 at 07:46
  • 1
    xVal was used with ASP.NET MVC 1.0 and currently Deprecated – Michael Freidgeim Jun 28 '12 at 21:47
3

One thing that I have found with the Enterprise Library blocks is that it can force you to use other blocks that you don't want/need. For instance, the Validation one might use the logging block, but you were happy with your own logging system. now your app logs things in different ways. That said, I have liked the look of the Validation block in the Ent Lib. I have not played with Spring.NET tho.

SteveM
  • 492
  • 3
  • 9
  • I never had this problem with the Validation Application Block. Can you point out the code or location where VAB is calling the Logging Application Block? – Steven Feb 09 '10 at 11:14
  • 1
    I've took a deeper look at this, but there are no direct calls from the Validation assemblies of the Enterprise Library to any of the logging assemblies. I think your application used the logging part directly. In my applications I only publish the assemblies that are specific to the VAB. For VAB 5.0 you need: `Common`, `Validation`, `ServiceLocation`, `Unity`, `Unity.Configuration`, and `Unity.Interception`. – Steven Aug 31 '10 at 07:53
  • This could have been on an older version. When I think I saw this it was version 2.0 of the Enterprise Library. – SteveM Sep 02 '10 at 20:29