ContosoUniversity icon indicating copy to clipboard operation
ContosoUniversity copied to clipboard

Dispatching messages from command handler after committing DB transaction

Open tafs7 opened this issue 8 years ago • 1 comments

I'm curious to understand, given this implementation, how you recommend handling the scenario where a message (e.g. queue) needs to be dispatched, ala domain events style, from a command handler, but only after the transaction is committed.

The DB transaction is being committed or rolled back via the MVC action filter's OnActionExecuted, which uses service locator to get the DbContext, and call the CloseTransaction. In other words, the transaction commit is being done outside the command handler. However, I'd like to dispatch an event message from the command only when the transaction is committed successfully, and from the command handler, I have no way of knowing when the transaction is committed.

Any thoughts on this?

tafs7 avatar Jun 01 '16 22:06 tafs7

Not from the command handler. You can do it from your ORM pretty easily though:

https://lostechies.com/jimmybogard/2014/05/13/a-better-domain-events-pattern/

jbogard avatar Jun 02 '16 13:06 jbogard