AggregateRoot 是否应该包含其他 AggregateRoot 的集合?
Should AggregateRoot contain collection of other AggregateRoot?
为了研究 DDD,我读了 this interesting topic 并发现了作者所说的一个新想法“关于不在产品中制作 'ProductReviews' 集合的论点 class”。因为“这两个实体之间没有真正的不变量”
Product
里面没有ICollection<ProductReview>
class。那么,问题是
- 它与 DDD 兼容吗?
- 这样做的优点和缺点是什么?
Does it compatible with DDD?
是的,将 ProductReviews 的逻辑集合的元素分离为 Product 聚合之外的聚合与 DDD 兼容。
也就是说,当以这种方式分离事物时,您通常不会尝试坚持事务性级联删除,如您链接的示例所示。
What is advantages and drawbacks when doing that?
通常有两个优点
如果不需要同步对模型两个不同部分的更改——也就是说你永远不需要一起更改两个部分来保持不变——那么将这些部分建模为单独的聚合会有所帮助使这种分离明确(因此更容易推理,等等)。
将模型分解为单独的聚合支持并行工作意味着我们可以减少进行更改所需的协调量。
如果模型的两个不同部分真的相互分离,你可以使用完全不同的技术来存储它们。
另一方面,它的缺点是,当您后来发现您毕竟需要协调对两个不同聚合的更改时,事情就会变得一团糟。此时您真正拥有的是数据模型中的单个 "logical" 聚合,该聚合已分解为领域模型中具有协调责任的多个聚合。
来自cqrs.nu
I know aggregates are transaction boundaries, but I really need to transactionally update two aggregates in the same transaction. What
should I do?
You should re-think the following:
- Your aggregate boundaries.
- The responsibilities of each aggregate.
- What you can get away with doing in a read side or in a saga.
- The actual non-functional requirements of your domain.
- If you write a solution where two or more aggregates are transactionally coupled, you have not understood aggregates.
为了研究 DDD,我读了 this interesting topic 并发现了作者所说的一个新想法“关于不在产品中制作 'ProductReviews' 集合的论点 class”。因为“这两个实体之间没有真正的不变量”
Product
里面没有ICollection<ProductReview>
class。那么,问题是
- 它与 DDD 兼容吗?
- 这样做的优点和缺点是什么?
Does it compatible with DDD?
是的,将 ProductReviews 的逻辑集合的元素分离为 Product 聚合之外的聚合与 DDD 兼容。
也就是说,当以这种方式分离事物时,您通常不会尝试坚持事务性级联删除,如您链接的示例所示。
What is advantages and drawbacks when doing that?
通常有两个优点
如果不需要同步对模型两个不同部分的更改——也就是说你永远不需要一起更改两个部分来保持不变——那么将这些部分建模为单独的聚合会有所帮助使这种分离明确(因此更容易推理,等等)。
将模型分解为单独的聚合支持并行工作意味着我们可以减少进行更改所需的协调量。
如果模型的两个不同部分真的相互分离,你可以使用完全不同的技术来存储它们。
另一方面,它的缺点是,当您后来发现您毕竟需要协调对两个不同聚合的更改时,事情就会变得一团糟。此时您真正拥有的是数据模型中的单个 "logical" 聚合,该聚合已分解为领域模型中具有协调责任的多个聚合。
来自cqrs.nu
I know aggregates are transaction boundaries, but I really need to transactionally update two aggregates in the same transaction. What should I do?
You should re-think the following:
- Your aggregate boundaries.
- The responsibilities of each aggregate.
- What you can get away with doing in a read side or in a saga.
- The actual non-functional requirements of your domain.
- If you write a solution where two or more aggregates are transactionally coupled, you have not understood aggregates.