领域驱动设计

发布于 2024-11-24 07:25:25 字数 235 浏览 3 评论 0原文

我正在寻求有关 DDD 的以下两点的澄清。

1.领域实体可以调用存储库吗?

2.领域服务可以调用存储库吗?

谢谢

编辑

找到了一套文档,详细介绍了 DDD 层,这就是它所说的;

此外,虽然通常存储库仅在应用程序层使用,但也可以例外,并根据需要从域服务调用存储库进行查询。但应该尽可能避免这种情况,以实现我们发展的同质化。

I'm looking for clarification on the following 2 points with regards to DDD.

1.Can a domain entity call a repository?

2.Can a domain service call a repository?

Thanks

Edit

Found a suite of documents that detailed the DDD layers in lots of detail and this is what it said;

Additionally, and although as a rule Repositories are only used from the Application layer, it is also possible to make exceptions, and make queries invoking Repositories from the Domain services as necessary. But this should be avoided as much as possible in order to achieve homogeneity in our developments.

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

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

发布评论

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

评论(2

聽兲甴掵 2024-12-01 07:25:25

我不会设计一个域实体来引用存储库。 “存储库”很少是域的一部分,并且会在域模型中引入技术问题。我发现最适合应用程序服务层的存储库。

I wouldn't design a domain entity to reference a repository. A "repository" is rarely a part of the domain and would introduce a technical concern into your domain model. I've found repositories to fit best at the application services layer.

朕就是辣么酷 2024-12-01 07:25:25

我不知道有这么严格的规则。 任何事情都可以做。

但我是这样做的。我不知道它是否符合 DDD:

  1. 通常域对象不调用存储库。他们不需要知道自己是否坚持下去。
  2. 服务编排域对象和存储库来满足用例。他们拥有工作单元并管理事务。

I'm not aware of such hard and fast rules. Anything can be done.

But here's how I do it. I don't know if it qualifies as DDD:

  1. Usually domain objects do not call repositories. They need not be aware whether they are persisted or not.
  2. Services orchestrate domain objects and repositories to fulfill use cases. They own units of work and manage transactions.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文