选择哪个验证框架:Spring Validation 或 Validation Application Block (Enterprise LIbrary 4.0)?

Which validation framework to choose: Spring Validation or Validation Application Block (Enterprise LIbrary 4.0)?(选择哪个验证框架:Spring Validation 或 Validation Application Block (Enterprise LIbrary 4.0)?)
本文介绍了选择哪个验证框架:Spring Validation 或 Validation Application Block (Enterprise LIbrary 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 和 .NET 的 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).

企业验证块也很少有负面影响.我的实体的属性最终有 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 Validation 或 Validation Application Block (Enterprise LIbrary 4.0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)