开发者

DDD, Can aggregate handle an event from another aggregate?

Is it right to ha开发者_如何学编程ndle an event in a aggregate published from another aggregate ? Or a domain should only handle commands ?

In my case, I have an application which manages settings. I have an aggregate for application and an aggregate for applicationGroup. When I want to create a settings for a specific group of applications, then the command is handled by my applicationGroup, then the applicationGroup publish an event GroupSettingsCreated, but does DDD say we can handle this event directly in my ApplicationAggregate ? Or should I handle this event in an event handler ,map it into a command then send it to my ApplicationAggregate ?

Thanks

John


If you're tempted to handle one aggregate's event inside another aggregate, the handler should be a child of the aggregate generating the event.

In other words, in this bounded context, Application should be a child of ApplicationGroup and ApplicationGroup.CreateSettings() should propagate settings to its child applications.

Another way to think of this: an "application group" might not be a true aggregate - but rather a convenience provided by the user interface.


John, I don't know of anything in DDD that speaks to your question. This is really a question of Event Driven Architecture (EDA) and Command Query Responsibility Segregation (CQRS).

To give more specific advice, I'd like to know what roles the application and applicationGroup entities play. BTW, they sound more like application/infrastructure concepts than domain concepts.

In general, I use commands where the next action is logically pushed from the source (the next action is a necessary next step). I use events when the action in question is logically a reaction to the upstream behavior (the upstream code is unaware of this reaction to what just happened).


You shouldn't do it in this way cause it will lead to a messy code. Instead, use sagas for am orchestration. Here is also good video from Andreas Öhlund on sagas in NServiceBus.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜