DDD:存储库应位于域层或应用程序层中

发布于 2025-02-05 21:25:46 字数 529 浏览 1 评论 0 原文

在具有依赖性反转原理的分层体系结构中,我们有一些应用程序服务(在应用程序层中)和一些域服务(在域层中)。

现在,我想对对象组成进行一些验证。在中,红皮书,在第5章中验证对象组成的某个地方:

,但最好使用域服务管理这种验证。域服务可以使用存储库来读取其验证所需的聚合实例。

  • 这是否意味着存储库接口生活在域层中?
  • 如果是,这些存储库接口是否有未售的真相? (也许他们只能通过ID获取聚合?)

我知道这个问题已经很多次。但是我发现大多数答案忽略了蓝色和红皮书

In a Layered Architecture with Dependency Inversion Principle we have some Application Services (in Application Layer) and some Domain Services (in Domain Layer).

Now I want to do some validations on Object Compositions. In the red book, on chapter 5 under Validating Object Compositions somewhere it says:

But it may be best to manage that kind of validation using a Domain Service. The Domain Service can use Repositories to read the Aggregate instances it needs to validate.

  • Doesn't this means that repository interfaces live in domain layer?
  • If yes, are there any un-told truth about these repository interfaces? (maybe they can only fetch aggregates by id?)

I know that this question has been asked so many times. But I find most of the answers neglecting the blue and the red book this stackexchange thread for example

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

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

发布评论

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

评论(1

呆橘 2025-02-12 21:25:46

这是否意味着存储库接口生活在域层?

是的,肯定会在域层中使用存储库接口,通常是域服务和应用程序服务(上面的一个层)是他们的消费者。

如果是,这些存储库接口是否有未售的真相? (也许他们只能通过ID获取聚合?)

存储库旨在获取和修改聚合根,无论是用于验证还是任何其他目的。 ID不一定要发生,它可能会随着情况的需求而发生其他参数。

Doesn't this means that repository interfaces live in domain layer?

Yes, repository interfaces live in the domain layer for sure and usually domain services and application services (a layer above) are their consumers.

If yes, are there any un-told truth about these repository interfaces? (maybe they can only fetch aggregates by id?)

Repositories are intended to fetch and modify aggregate roots, be it for validation or any other purpose. The fetch doesn't necessarily have to happen with id, it may happen with other parameters as situation demands.

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