In Lagom, aggregate roots [DDD] are each represented as a PersistentEntity. Is it possible for one PersistentEntity to resolve and hold a reference to a different PersistentEntity? I could not find any Lagom examples which illustrated that scenario.
Asked
Active
Viewed 348 times
1 Answers
2
Yes, you can hold the identifier (entity id) of another PersistentEntity in your entity's state (events and snapshots). You can inject the PersistentEntityRegistry into your PersistentEntity class just like you would into your service impl. When you want to send a command to the other entity you simply get the PersistentEntityRef from the registry by type and entity id.
In case what you're doing is not "fire-and-forget" but you send a command to another entity (from your command handler I'm assuming) and want to do something when the reply arrives back, be careful how you process that reply, as the interaction is asynchronous. You can read more about this case in the following thread: Lagom: Asynchronous Operations in Command Handlers

Michal Borowiecki
- 4,244
- 1
- 11
- 18