Returning Domain Event Pattern
I have a some questions concerning the returning domain event pattern (chapter 18).
1-How should the DB transactions shoule be handle?
Transaction must be handle in application services. So I can do some actions on an aggregate root at this layer, persisting it in the DB, closing the transaction, and handling the accumulated domain events on the aggregate after that, using a dispatcher. But is it the responsability of the dispatcher to create new transaction, one for each event it process, or should the processing of an event be wrapped in a transaction at the same level where we iterate on the domain events returned by the aggregate (in the application service)?
2-What is your opinions about hooking the transaction completion using the ORM (i.e.: IPostInsertEventListener, IPostDeleteEventListener, IPostUpdateEventListener of NHibernate) instead of manually doing it in the application service? Does it add too much coupling? Is it better because it does not require the same code being written at each use case (the domain event looping on the aggregate and potentially the new transaction creation if it is not inside the dispatcher)?
|