DDD:关于聚合边界的问题

发布于 2024-09-12 17:59:12 字数 347 浏览 2 评论 0原文

我有一个复杂的场景,其中两个聚合边界有点相互矛盾。

我有两个实体:请求和使命。用户创建请求,然后他可以创建任务并将现有请求分配给任务。

请求和任务可以独立创建。换句话说,我在创建请求时不需要有任务,反之亦然。

所以我假设我们这里有 2 个不同的聚合:请求聚合和任务聚合,每个实体都是其自己聚合的根。

然而,我们有一个不变量违反了这一假设:您可以推迟或取消任务,这会导致分配给该任务的所有请求的状态相应更新。

如果请求和任务位于两个不同的聚合中,我如何强制执行此约束?如果我将它们放在同一个聚合中,则无法分辨谁是聚合根,因为每个实体都可以独立创建。

有什么建议吗?

莫什

I have a complicated scenario in which two aggregate boundaries sort of contradict each other.

I have 2 Entities: Request and Mission. User creates Requests and later on he can create Missions and assign existing Requests to a Mission.

Requests and Missions can be created independently. In other words, I don't need to have a Mission when creating a Request and vice versa.

So I'm assuming we have 2 different Aggregates here: Request Aggregate and Mission Aggregate, with each Entity being the root of its own Aggregate.

HOWEVER, we have an invariant that violates this assumption: You can Postpone or Cancel a Mission, which causes the Status of all Requests assigned to it to be updated accordingly.

How can I enforce this constraint if Request and Mission are in two different Aggregates? If I put them in the same Aggregate, it's not possible to tell who is the Aggregate Root because each Entity can be created independently.

Any advice?

Mosh

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

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

发布评论

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

评论(2

难忘№最初的完美 2024-09-19 17:59:12

你已经走在正确的轨道上了。您缺少的部分是:聚合可以包含其他聚合。

您的任务可以触发状态 对其包含的任何Requests 进行更改。

You're on the right tracks already. The piece you're missing is this: Aggregates can contain other aggregates.

It's OK for your Mission to trigger Status changes on any Requests that it contains.

甜心 2024-09-19 17:59:12

我的建议是使用事件模式。当一个同意门的状态发生变化时发布事件。这可以在处理程序中使用,该处理程序将能够更改其他聚合状态。希望这是有道理的。

my suggestion would be that to use eventing pattern. When one Agreegate's state is changes publish event. This can be consumed in handler which will have ability to change other Aggregates state. Hope it makes sense.

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