lundi 29 octobre 2018

What should the UnitOfWork pattern be actually handling

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.

interface IUoW : IDisposable 
{
    SqlConnectionProvider Connection { get; }

    IAtomicTransaction StartTransaction();
}

So the IUoW concrete implementation should handle only connection to a SQL Provider and keeping track to any changes

Committing should be something like this

interface IAtomicTransaction : IDisposable 
{
    void Commit();

    void Rolleback();
}

Is this true ? or I just didn't understand the purpose of a UoW ? The thing is that I see that UoW does everything in lots of posts and I don't fell it should do so.

Aucun commentaire:

Enregistrer un commentaire