选择哪种验证框架:Spring验证或验证应用程序块(企业库4.0)? [英] Which validation framework to choose: Spring Validation or Validation Application Block (Enterprise LIbrary 4.0)?

查看:75
本文介绍了选择哪种验证框架:Spring验证或验证应用程序块(企业库4.0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为大型应用程序选择一种验证框架,尽管这两种选择似乎都很诱人,但我想知道在提交一个或另一个之前是否应该了解任何特定的利弊。

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.

推荐答案

使用属性验证不是我认为的最佳解决方案。首先,您必须在域模型中引用基础结构。其次,您没有机会向已编译的类添加验证。最后,您无法使用属性来验证复杂的逻辑,而必须对实体进行Validate方法,这似乎很尴尬。

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.

在我看来,验证应分离到不同的对象。例如IValidator,您可以在其中将验证定义为规则。使用 xVal 之类的框架有助于使用JavaScript在表示层中进行验证。

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.

您可能要查找 xVal 的codeplex.com/ rel = noreferrer> FluentValidation。 NHibernate Validator 1.2 alpha也具有流畅的语法,并且已与xVal集成(不确定alpha,但应该为1.0)。

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的负面影响也很少。我实体的属性最终具有3行属性,并使可读性变差。尝试使用AND或OR运算符添加验证也很痛苦。

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.

这篇关于选择哪种验证框架:Spring验证或验证应用程序块(企业库4.0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆