NHibernate Validator 动态规则
我正在使用 Nhibernate,并且我要求验证规则必须及时更改。我将使用的框架是NHibernate validator,但我真的不知道如何制定动态规则,使用实体类中的xml文件或属性进行验证非常简单,但问题是使该规则可更新。有办法实现这一点吗?
I'm using Nhibernate and I have a requirement that the validation rules must change in time. The framework I'll use is NHibernate validator, but I don't really know how to make dynamic rules, the validation is quite simple with xml files or attributes in the entity class, but the catch is to make this rules updatable. Is there a way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,既然没有人回答这个问题,我将解释如何实现它。它可以通过类中的特殊属性来完成,例如 [Email] [NotNull] [NotEmpty] 等,并且可以使用 xml 文件更改/覆盖它们。在 NHibernate 验证器的配置文件中,为每个应控制的类添加标签,如下所示:
并将 default_validator_mode 属性更改为 OverrideAttributeWithExternal
希望这会有所帮助:)
Well, since nobody answered this I'll explain how can it be achieved. It can be done with special attributes within the class like [Email] [NotNull] [NotEmpty] etc, and they can be changed/overridden with xml files. In the configuration file of the NHibernate validator add tags for each one of the classes that should be controled like this:
and change the default_validator_mode property to OverrideAttributeWithExternal
Hope this helps :)
NHibernate Validator 不适合动态规则,相反,它是一个约束验证框架,用于验证对象。除此之外,您还可以使用流畅的配置来实现一些活力
http://fabiomaulo.blogspot.com/2010/01/nhibernatevalidator-changing -validation.html
NHibernate Validator isn't suitable for dynamic rules, instead of that, is a Constraints Validation Framework, to validate objects. Besides that, you may achieve some dynamism using fluent configuration
http://fabiomaulo.blogspot.com/2010/01/nhibernatevalidator-changing-validation.html