C# 模型验证 - 验证应用程序块还是数据注释?

发布于 2024-08-17 01:25:31 字数 213 浏览 12 评论 0原文

我想将验证器属性添加到我的域模型(在 ASP.NET MVC 应用程序中),并且我试图在 2 个框架(验证应用程序块和 DataAnnotations)之间做出决定。它们似乎执行类似的任务,因此我想选择将来最受支持/使用的一个。 DataAnnotations 似乎较新(并且从 3.5 SP1 开始内置于框架中),所以人们认为验证应用程序块会过时吗?

[标记为社区 Wiki,因为这是主观的]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-08-24 01:25:31

我也一直在问这个问题,最近决定使用企业库。我已经能够结合使用 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


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

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.

东北女汉子 2024-08-24 01:25:31

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

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

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

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.

佼人 2024-08-24 01:25:31

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文