Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD, Can aggregate handle an event from another aggregate?

Is it right to handle 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

like image 609
John Avatar asked Aug 04 '11 07:08

John


1 Answers

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.

like image 197
Jeff Sternal Avatar answered Oct 07 '22 04:10

Jeff Sternal