Triggering a domain event from Aggregate A within a service of Aggregate B #201
Unanswered
SteveG-WeInvest
asked this question in
Q&A
Replies: 1 comment
-
|
If you need to coordinate multiple aggregates, Domain Services can help with that (also Application Services if logic involves calling external APIs/databases).
You can just make a method in Aggregate A that creates multiple entities at once and emits event only once. If your use case doesn't allow it, then just do it in the service IMO. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I’m new to DDD principles and I’m having trouble understanding how to trigger a domain event for Aggregate A from within a service that belongs to Aggregate B.
I understand that domain events should ideally be raised from within the domain, and therefore are usually tied to an entity’s lifecycle. However, my use case is a bit different:
I retrieve data from a third-party API and use it to create multiple entities within Aggregate A. After that, I need to update entities in Aggregate B based on the entities created in Aggregate A (for example, calculating a score depending on how many A entities are related to each B entity).
I want to avoid triggering an event in Aggregate A's domain logic, because it would fire the event n times — once for each created entity. Instead, I need to trigger the event only once, after the data retrieval and creation process is complete. This would likely happen in a service or an event listener.
What would be the right way to approach this in DDD?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions