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

后端 未结 2 1658
慢半拍i
慢半拍i 2020-12-29 16:05

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

2条回答
  •  失恋的感觉
    2020-12-29 16:20

    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.

提交回复
热议问题