开发者

C# Model Validation - Validation Application Block or DataAnnotations?

I want to add validator attributes to my domain models (in an ASP.NET MVC app), and I'm trying to decide between 2 frameworks, the Validation Application Block and DataAnnotations. They appears to do similar tasks, so I want to pick the one which will be the most supported/used in the future. It seems DataAnnotations are newer (and built into the framework as of 3.5 SP1), so do people think the Validation Application Block will become obsolete?

[开发者_高级运维Marked as Community Wiki as this is subjective]


I have been asking this question as well and have recently decided to use Enterprise Library. I have been able to use a combination of the Unity Framework & the Validation Block to attribute & validate my classes & methods with little trouble. Both frameworks are included in EntLib.

As far as continued support is concerned, the next version of Enterprise Library is currently in Beta 2 (EntLib 5.0) and is aiming for a mid April Release. You can access the current beta here, http://entlib.codeplex.com/wikipage?title=EntLib5%20Beta2.

Also, after reading through the change log for version 5 I noticed that they are including support for DataAnnotations as well.

"Support for .NET framework System.ComponentModel.DataAnnotations data annotation attributes has been added to the block, and the validators can be used anywhere you would use a Data Annotation attribute. For more information see Using Data Annotation Attributes in the included CHM file."

http://entlib.codeplex.com/wikipage?title=EntLib5Beta2ChangeLog&referringTitle=EntLib5%20Beta2#lab


So, it looks like Enterprise Library will continue to be supported.


MVC2 will support multiple validation frameworks. To quote the great Scott Guthrie "ASP.NET MVC 2’s validation features are designed to make it easy to plug-in any type of validation architecture".

As DataAnnotations uses a attribute based approach, Validation Application Block will not get obsolete, because it also supports a configuration based approach and validation of multiple rule sets which is useful in many scenario's. you can expect that a future version of the VAB will have built in support for MVC 2.

UPDATE: In the newest version of the Validation Application Block, version 5, the validation attributes of the VAB inherit from the base validation attribute of DataAnnotations. This means that VAB now builds directly on top of DataAnnotations and applications that can handle DataAnnotations can also handle the attributes defined by VAB.


DataAnnotations are supported by both MVC 2 and Asp.net 4.0 DynamicData. I'd say Validation Application Block will become obsolete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜