Skip to content

Why events publish method in Repository Class? #129

Answered by Sairyss
jovicon asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@AlexSun98
Comment options

@Sairyss
Comment options

@nilaxann65
Comment options

@AlexSun98
Comment options

@Sairyss
Comment options

Answer selected by jovicon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants