4

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]

4

3 回答 3

7

我也一直在问这个问题,最近决定使用 Enterprise Library。我已经能够使用 Unity 框架和验证块的组合来属性和验证我的类和方法,并且没有什么麻烦。这两个框架都包含在 EntLib 中。

就持续支持而言,企业库的下一个版本目前处于 Beta 2 (EntLib 5.0) 中,目标是在 4 月中旬发布。您可以在此处访问当前的测试版,http ://entlib.codeplex.com/wikipage?title=EntLib5%20Beta2 。

此外,在阅读了版本 5 的更改日志后,我注意到它们也包括对 DataAnnotations 的支持。

“对 .NET 框架 System.ComponentModel.DataAnnotations 数据注释属性的支持已添加到块中,并且验证器可以在任何使用数据注释属性的地方使用。有关更多信息,请参阅包含的 CHM 文件中的使用数据注释属性。 "

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


因此,看起来企业库将继续受到支持。

于 2010-04-01T14:54:32.750 回答
3

MVC2 将支持多种验证框架。引用伟大的Scott Guthrie的话“ASP.NET MVC 2 的验证功能旨在使插入任何类型的验证架构变得容易”。

由于 DataAnnotations 使用基于属性的方法,验证应用程序块不会过时,因为它还支持基于配置的方法和多个规则集的验证,这在许多场景中都很有用。您可以预期未来版本的 VAB 将内置对 MVC 2 的支持。

更新:在最新版本的验证应用程序块版本 5 中,VAB 的验证属性继承自 DataAnnotations 的基本验证属性。这意味着 VAB 现在直接构建在 DataAnnotations 之上,可以处理 DataAnnotations 的应用程序也可以处理 VAB 定义的属性。

于 2010-02-09T11:03:24.333 回答
2

MVC 2 和 Asp.net 4.0 DynamicData 都支持 DataAnnotations。我会说验证应用程序块将过时。

于 2010-01-05T16:45:29.230 回答