NHibernate 验证器还是 Fluent 验证器?
我使用NHibernate。我需要决定如何验证域实体。你有什么建议吗?使用 NHibernate 和 Fluent Validation 会有什么问题吗?
I use NHibernate. I need to decide how validate domain entities. What do you recommend? Are there any troubles if use NHibernate with Fluent Validation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我所知道的 O/RM 工具中,NHibernate 在域类的 C# 代码中占用的空间最小。它几乎允许与 POCO 一起工作,同时完全忘记依赖关系。这也正是 FluentValidation 所允许的。所以对我来说这似乎是一段幸福的婚姻。
但在不了解更多背景信息的情况下,我不敢推荐或建议反对任何验证工具或框架。有很多候选人,他们也愿意与 NHibernate 合作。数据访问和验证是两个不同的问题,应该(并且可以)彼此分开。
Of the O/RM tools I know, NHibernate has the smallest footprint in the C# code of domain classes. It almost allows working with POCO's while being totally oblivious of dependencies. That is exactly what FluentValidation allows too. So it seems like a happy marriage to me.
But I wouldn't dare recommend or advise against any validation tool or framework without knowing more of your context. There are many candidates and they would work with NHibernate as well. Data access and validation are two different concerns that should (and can) be separated from one another.
Fluent 验证非常适合用户输入验证,并且可以用于简单的业务规则。但它没有与 NHibernate 集成。这意味着除了您的自定义代码之外,没有什么可以阻止 NHibernate 保存无效实体。
另一方面,有一个 NHibernate 验证器项目。它与 nhibernate 集成,并且不会让您保存无效实体。
Fluent validation is really good for user input validation, and can be used for simple business rules. But it has no integration with NHibernate. That means that nothing would prevent NHibernate from saving not valid entity except your custom code.
On other hand there is a NHibernate validator project. It has an integration with nhibernate, and it won't let you to save not valid entity.
一般来说,您的域不应该知道您的 ORM。应将其隔离保存。所以我的答案是:
我看不到 NH 和 FNH 验证有任何问题,但尽可能保持域隔离。
Generally your domain shouldn't know about your ORM. It should be kept in isolation. So my answer is:
I Can not see any issue with NH and FNH Validation, but keep domain in isolation as much as possible.