Hi Michael,
and I fully agree with him. You should never do anything one more than one aggregate at a time.
But there are more motivations for the UnitOfWork in Axon.
I don't like this approach:
aggregate = repository.load(...);
aggregate.doSomething();
repository.save(aggregate);
for several reasons. First: of course I want to save! I am not making these changes for kicks. Second: it provides some implementation details in the repository interface. We need to tell it so persist our changes. Third: it's the same code, over and over.
In my command handlers, I have extracted the repository.load(id) into a separate method, called onMyAggregate(id).
This allows me to express what I want in more natural wording:
void handleMyCommand(DoSomethingCommand cmd) {
onMyAggregate(cmd.getIdentifier()).doSomething();
}
I agree, the UnitOfWork does allow users to break the one-aggregate-at-a-time rule. But I don't want Axon to enfore CQRS rules, just to make it easier to build applications that conform to them.
Cheers,
Allard