领域驱动设计- UI 直接调用存储库

发布于 2024-10-19 15:10:08 字数 76 浏览 5 评论 0原文

在领域驱动设计中,是否存在 UI 层不应调用数据访问/存储库层的硬性规则?如果不是,那么它应该如何以正确的方式工作?

谢谢

In domain driven design, is there any hard and fast rule that the UI layer should not make a call to the data access/repository layer? If not, then how should it work the correct way?

Thanks

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

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

发布评论

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

评论(3

鸠魁 2024-10-26 15:10:08

通常,您将通过应用程序层(控制器)处理对数据访问层/存储库的调用,该应用程序层调用基础设施层中的数据访问。

然而,Ayende(NHibernate 出名)对于这个“规则”有一些有趣的观点。

http://ayende.com/Blog /archive/2009/04/23/night-of-the-living-repositories.aspx

Normally, you would handle calls to the Data Access Layer/Repository via an Application Layer (controller) which calls data access in the Infrastructure layer.

However, Ayende (of NHibernate fame) has some interesting points regarding this "rule."

http://ayende.com/Blog/archive/2009/04/23/night-of-the-living-repositories.aspx

×眷恋的温暖 2024-10-26 15:10:08

有些人喜欢通过应用程序服务路由一切。我个人不喜欢 那种方法

我认为“一切都通过服务”方法对我来说听起来合理的唯一原因是,如果您明确希望如此,以便在客户端和域模型之间划出大胆而有力的界限。

它与使用/避免存储库模式非常相似。引用阿延德的话:

如果你不想要层/层边界,就直接使用 nhibernate

正是 seam 的必要性应该会驱动您直接使用 DA 的需求。
如果您不需要它,您最终会添加大量噪音

Some people enjoy routing everything through application services. I personally dislike that approach.

Only reason I see which could make "everything goes through services" approach sound reasonable to me is if You explicitly want it to be so in order to draw bold and strong line between client and domain model.

It's quite similar to using/avoiding repository pattern. Quoting Ayende:

If you don’t want a LAYER/TIER boundary don’t have one just use nhibernate directly

It's that necessity of seam that should drive Your need of direct DA usage.
If You don't need that, You will end up adding heavy noise.

仙气飘飘 2024-10-26 15:10:08

不,没有“硬性规定”。

如果您正在构建一个简单的应用程序,只需注入一个 ISession(如果您不使用 NHibernate,则注入类似的内容)。

当事情变得更加复杂时,我建议您查看聚合根、存储库和 UI 模式,例如 MVVM、被动视图和 MVC。

“正确的方法”取决于您的环境以及您计划如何测试。

No, no "hard and fast rule".

If it's a simple app you're building, just inject an ISession (or the like if you're not using NHibernate).

When things get more complex, I'd recommend you have a look at aggregate roots, repositories, and UI patterns such as MVVM, Passive View, and MVC.

"The correct way" depends on your context, and how you're planning to test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文