Aggreate not updating its state in repo.


User Story: I have a preopen cycle as a part of which I have to run 3 reports sequentially. The report run events are sent to an external system which publishes events based on the report completion.
The complete cycle is Async and ever report runs after a previous is completed.

Preopen Cycle Start

  • Report 1
  • Report 2
  • Report 3
    Preopen Cycle End

Domain Model

Preopen Aggregate

  • List reports
  • business logic to push events to run reports

Preopen Saga

  • Receives the events from external system and then issues specific commands.

When the first report runs and is completed, the external system sends a event and I have to update my aggregate for that event. But seems like my aggregate is not getting updated and it always has the old state so the process never ends.
When I go to report 2 and load the aggregate for report 1 from the repo it still shows the report 1 status is pending.

Hi Ajinkya,

note that Aggregates don’t listen to external events. You can use Event Sourcing on aggregates, in which case they will have Event(Sourcing)Handlers, but these are only ever invoked by events that were applied by the aggregate itself.

If you have external events that need to cause side-effects in an aggregate, you will need a “regular” event handler for those and send a command from there. Alternatively, you could use Sagas if these handlers need to maintain state during the process.

Hope this helps.