Skip to content
Mogens Heller Grabe edited this page Sep 13, 2015 · 9 revisions

If you intend to do something with a database in a message handler, and you want the handling of the incoming message to function as a unit of work, then you might want to check out this page :)

What is a unit of work?

You can read Fowler's ubiquitous description if you're interested in the details, but it basically boils down to this: You want to do stuff either fully, or not at all.

Usually, when your "stuff" is "doing work in a database", you will use that database and its ability to

  • start a transaction before you start doing stuff
  • do stuff as part of the transaction
  • commit the transaction if all goes well
  • roll back the transaction if something fails

These things can of course be implemented in an ad-hoc fashion whenever you need it, but it's usually better implemented by hooking into Rebus in the right places - this is what we'll talk about here.

Hooking into Rebus in the right places

Rebus receives each message inside an ITransactionContext which [can always be accessed somehow|Accessing the transcation context].

Clone this wiki locally