What should a UoW be actually handling ?
The way I see it, the UoW should not be handling commits and rollbacks. It should just provide means to do so, and should only be responsible with tracking changes on objects that are about to be committed such that if they are in some inconsistent state or something has changed, the transaction should fail ?
So the way I see a UoW is something like this.
public interface IUnitOfWork : IDisposable
{
IAtomicTransaction BeginTransaction();
Task<object> SaveAsync<TEntity>(TEntity entity);
Task UpdateAsync<TEntity>(TEntity entity);
Task RemoveAsync<TEntity>(TEntity entity);
}
Committing should be something like this
interface IAtomicTransaction : IDisposable
{
void Commit();
void Rolleback();
}
Take for example this post (and not only this but there are many like it),
If you look you will see that it uses ISession within the repository, which I find it to be a mistake since it will directly link the Repository (your business) to NHibernate's ISession. Shouldn't the UoW take this responsibility? Should you start changing your business implementation because you change the framework ? Shouldn't the UoW act as an Adapter, something like an anti-corruption layer ?