I开发者_运维技巧 am confused with when to use domain events and when to use double dispatch. Udi encourages us to use domain events to maintain encapsulation of model and away from anemic design, but in my opinion domain events can only be used after the operation has been performed or ended abruptly, not at the time when the operation is in progress.
For example: while solving some business logic I need to access the repository, and then based on the value, I can raise domain events. But the question is how the model can access repository at the time of solving business logic, here in my opinion we could use double dispatch.
Please tell me, are the above statements are valid or not?
There's been quite much talking about this.
I personally aggree with Szymon Pobiega:
My own rule of thumb is use Domain Events (as desscribed by Udi) as a preferred way of IoC when interaction can be made one-way. If it can't, I use double dispatch.
For eg -: while solving some business logic i need to access repository, and then based on value, i can raise domain events.
Your aggregate root should contain everything You need to perform operation. There shouldn't be a need for repository while doing something. Aggregate root draws transactional boundaries.
精彩评论