Domain event publisher inside DomainEventsDispatcher #326
Replies: 1 comment 2 replies
-
This architecture (as any other) is opinionated on the topic of DomainEvent. In general you have two takes: The architecture of this repo obviously goes with the (A). IMO This gives an elegant way to implement "transactional workflows" - when you need to actually affect multiple aggregates inside the same transaction - instead of having procedural code (in your command handler for example) making calls on one aggregate after another, you instead react to a DomainEvents. I don't think there's any rule or best practice that this approach breaks. It's just a take that may or may not be suitable for your use case. This repo also gives you "out of transaction" handlers via IDomainEventNotifications. |
Beta Was this translation helpful? Give feedback.
-
Hello @kgrzybek
First of all, thank you for letting the community learn from this repository.
I have a question about the
DomainEventsDispatcher
class. One of the things it does is read domain events published by an aggregate to be further processed as part of the very same transaction if need arises. For example,UserRegistrationConfirmedDomainEvent
is published byUserRegistration
aggregate, which in turn is handled byUserRegistrationConfirmedHandler
as a subscriber. All this happens in the piece of code shown below:Why would the class want to expose such an option?
If I understand the structure of the flow correctly, the approach allows changing the state of two or even more aggregates within the same transaction boundary, depending on the number of subscribers to the original event. In other words, there is nothing to stop us from modifying the state of not just one but many aggregates at the same time. Is that acceptable? What would the best practice be here?
Beta Was this translation helpful? Give feedback.
All reactions