DDD:关于聚合边界的问题
我有一个复杂的场景,其中两个聚合边界有点相互矛盾。
我有两个实体:请求和使命。用户创建请求,然后他可以创建任务并将现有请求分配给任务。
请求和任务可以独立创建。换句话说,我在创建请求时不需要有任务,反之亦然。
所以我假设我们这里有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你已经走在正确的轨道上了。您缺少的部分是:聚合可以包含其他聚合。
您的
任务
可以触发状态
对其包含的任何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 triggerStatus
changes on anyRequests
that it contains.我的建议是使用事件模式。当一个同意门的状态发生变化时发布事件。这可以在处理程序中使用,该处理程序将能够更改其他聚合状态。希望这是有道理的。
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.