Hi Michael,
the Unit Of Work was originally introduces to enable a single command to execute logic on more than one aggregate. If the aggregate is the transactional scope (which according to CQRS, it is), then we’re actually talking about more than one request here.
Currently, in Axon, the Unit Of Work has a more central role in managing the work done by command handlers. The Unit Of Work currently keeps track of the aggregates that have been loaded by the repositories and persists them when the UnitOfWork is committed. According to Martin, that’s exactly what a UoW should do, if I understand correctly.
Martin Fowler: "When you’re pulling data in and out of a database, it’s important to keep track of what you’ve changed; otherwise, that data won’t be written back into the database. Similarly you have to insert new objects you create and remove any objects you delete. […] A Unit of Work keeps track of everything you do during a business transaction that can affect the database. When you’re done, it figures out everything that needs to be done to alter the database as a result of your work. "
In Axon, when I talk about a transaction, I mostly mean an underlying database transaction in which changes are done to the database. However, that is completely optional. For example, a Unit could use an underlying database transaction when it is trying to write all its updates to the database.
That this answer your question?
Cheers,
Allard