Which validation framework to choose: Spring Validation or Validation Application Block (Enterprise LIbrary 4.0)?

﹥>﹥吖頭↗ 提交于 2019-11-30 05:36:43

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.

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.

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 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.

One thing that I have found with the Enterprise Library blocks is that it can force you to use other blocks that you don't want/need. For instance, the Validation one might use the logging block, but you were happy with your own logging system. now your app logs things in different ways. That said, I have liked the look of the Validation block in the Ent Lib. I have not played with Spring.NET tho.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!