Hi,
I’m wondering if anyone can shed some light on why events are duplicated in the following scenario:
CommandA received
CommandHandlerA on AggregateA handles CommandA and calls apply() to apply a new EventA.
CommandHandlerA issues CommandB targeting AggregateA
CommandHandlerB on AggregateA handles CommandB
CommandHandlerB completes
CommandHandlerA completes
The eventsToPulbish property of the DefaultUnitOfWork instance that is committed when CommandHandlerA completes contains two EventA instances. Both instances are the same (ie, the have the same object id).
If I issue a further command from CommandHandlerB for a CommandC, then the eventsToPulbish will contain the same EventA three times.
Is this by design? A bug? Or something wrong with what we’re doing? I’m suspecting the latter. I’m not sure if it’s best practice for a command handler to be issuing a subsequent command to the same aggregate, and perhaps that needs refactoring.
Thanks
Paul