-
I want to know why it is ok to publish our events in our base repository class |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Because it is a convenient place to do so for this project. We persist entities using a repository, so at the time of persisting we can publish all events and make sure everything is saved at once before returning. |
Beta Was this translation helpful? Give feedback.
Because it is a convenient place to do so for this project. We persist entities using a repository, so at the time of persisting we can publish all events and make sure everything is saved at once before returning.
We save all the event handlers results as a part of a single transaction, meaning that if you save entity A that emits multiple events, and you have event handlers that save entities B and C, saving entity A will make sure entity B and C are also updated in the same transaction, so repository becomes a convenient place to publish pending events.