Loading a second aggregate during a saga?
jdkrebs opened this issue · 5 comments
I have a scenario where I need to handle an event in a saga and depending on the state of a second aggregate, possibly fire a new command.
The ability to load that second aggregate (of a different type) doesn't appear to be present in a saga. Any thoughts on how one would approach this particular problem?
Could we add the ability to load another aggregate in a saga?
aggregates only live in the domain...
to solve your problem you need to denormalize some events to have you desired state... and when your triggering event occures you can check that state and trigger s new command...
The problem is, the viewmodels/denormalized data structures projected are not guarantied to be the latest data (as just because a command has been accepted and an event has been stored doesn't mean it has been projected yet) so executing commands based on viewmodels/denormalized events would not work in this scenario.
No guaranty, but you can connect to the eventstore in the saga and fetch all events of you aggregate..... or you can write your own commandHandler in domain that would at the end (after writing the events to the store) handle your new command...
Alright, The approach I was going to take was to fetch all of the events of the aggregate and go that route. It will work for sure, just wanted to make sure I wasn't missing something with one of your libraries.
Ok ;-)
But remember: it's always stale data