一系列简单的聚合根问题(领域驱动设计)

发布于 2024-09-02 00:03:21 字数 230 浏览 1 评论 0原文

关于领域驱动设计中的聚合根,我有几个(希望如此)简单的问题:

  1. 可以将聚合根作为另一个聚合根的属性吗?
  2. 给定实体可以存在于两个或多个聚合根中吗?

我的最后一个问题有点复杂。我有一个网站,其中有一些真正属于“网站”聚合根的实体。它们是“新闻”、“产品”和“用户”。数据库中没有“网站”表,但“网站”似乎是这三个实体的良好聚合根。 这通常是如何实现的?

谢谢!

I have a few (hopefully) simple questions about aggregate roots in domain driven design:

  1. Is it okay to have an aggregate root as a property of another aggregate root?
  2. Is it okay to have a given entity inside two or more aggregate roots?

My final question is a bit more involved. I have a website that has a few entities that really belong to a "website" aggregate root. They are 'News', 'Products', and 'Users'. There isn't a 'Website' table in the database, but a 'Website' seems like a good aggregate root for these three entities.
How is this usually achieved?

Thanks!

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

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

发布评论

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

评论(1

提赋 2024-09-09 00:03:21

您是否有跨越整个网站的一致性规则(涉及多个新闻产品和用户)?如果不是,这些实体(新闻、产品、用户)就是您聚合根的良好候选者。

聚合根主要功能是提供一致性和事务语义边界。

回答你的问题:

  1. 是的,只要这样就可以了
    引用的聚合根不是
    在任何操作期​​间修改
    含有AR。这连接到
    一致性边界:
    跨多个业务
    不保证聚合
    产生一致的结果,以便他们
    应该避免

  2. 不,一个实体
    (不是 AR)可以是
    只有一个聚合。

Do you have any consistency rules spanning the whole website (concerning multiple news products and usesrs)? If not, these entities (news, products, users) are good candidates for being you aggregate roots.

Aggregate root main function is to provide consistency and transaction semantics boundary.

To answer you questions:

  1. Yes, it is ok as long as this
    referred aggregate root is not
    modified during any operation of the
    containing AR. This is connected to
    the consistency boundaries:
    operations spanning multiple
    aggregates are not guarantied to
    produce consistent results so they
    should be avoided

  2. No, an entity
    (which is not AR) can be a part of
    only one aggregate.

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