如果配置了 ValidatorMode.UseExternal,则 ValidatorEngine.Validate 返回 null(无错误)

发布于 2024-09-06 07:52:57 字数 261 浏览 1 评论 0原文

我正在将 nhibernate 验证器集成到我的应用程序中,并且属性一切正常 但是一旦我创建 *.nhv.xml 文件并将我的验证规则移到那里(作为嵌入资源)

ValidatorEngine.Validate(entity)
returns wrong (actually nothing and my InvalidValue[] collection is empty

我同意任何评论/建议

i am integrating nhibernate validator into my application and and everything is fine with attributes
but as soon as I create *.nhv.xml files and move my validation rules there (as embedded resource)

ValidatorEngine.Validate(entity)

returns wrong (actually nothing and my InvalidValue[] collection is empty

I appropriate any comment/advise

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国产ˉ祖宗 2024-09-13 07:52:57

问题是由于 nhibernate 验证器的配置部分
首先是

NHibernateSharedEngineProvider

should get assigned to

NHibernate.Validator.Cfg.Environment.SharedEngineProvider

then
we have to call the current engine's

Configure

not a new instance
of ValidatorEngine
so the full configuration section may look like this:


           var provider = new NHibernateSharedEngineProvider();
           NHibernate.Validator.Cfg.Environment.SharedEngineProvider = provider;

var nhvConfiguration = new FluentConfiguration(); nhvConfiguration .SetDefaultValidatorMode(ValidatorMode.UseExternal) .Register(Assembly.Load("assembley name") .ValidationDefinitions()) .IntegrateWithNHibernate .ApplyingDDLConstraints() .And .RegisteringListeners(); var validatorEngine = NHibernate.Validator.Cfg.Environment.SharedEngineProvider.GetEngine(); validatorEngine.Configure(nhvConfiguration);

The problem was because of configuration part of the nhibernate validator
first the

NHibernateSharedEngineProvider

should get assigned to

NHibernate.Validator.Cfg.Environment.SharedEngineProvider

then
we have to call the current engine's

Configure

not a new instance
of ValidatorEngine
so the full configuration section may look like this:


           var provider = new NHibernateSharedEngineProvider();
           NHibernate.Validator.Cfg.Environment.SharedEngineProvider = provider;

var nhvConfiguration = new FluentConfiguration(); nhvConfiguration .SetDefaultValidatorMode(ValidatorMode.UseExternal) .Register(Assembly.Load("assembley name") .ValidationDefinitions()) .IntegrateWithNHibernate .ApplyingDDLConstraints() .And .RegisteringListeners(); var validatorEngine = NHibernate.Validator.Cfg.Environment.SharedEngineProvider.GetEngine(); validatorEngine.Configure(nhvConfiguration);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文