Unit Of Work

With databases, unit of work is a way to wrap a transaction without adding hard dependencies against the data source.

The library contains an IUnitOfWork which also is specialized into IAdoNetUnitOfWork to allow you to work with ADO.NET while abstracting away that detail from your business layer.

You can do this in your business layer:

using (var uow = UnitOfWorkFactory.Create())
    var repos = new AccountRepository(uow);
    repos.Insert(new User(/*....*/));


While this is done in your data layer:

public class AccountRepository
    IAdoNetUnitOfWork _unitOfWork;
    public AccountRepository(IUnitOfWork uow)
        //Violation of Liskovs Substituation Principle in theory,
        // but will unlikely causing and problems in reality since you probabaly wont
        // change data storage without going through the data layer in detail.
        _unitOfWork = (IAdoNetUnitOfWork)uow;
    public void Insert(Account account)
        //will automatically enlist the command in the current transaction
        using (var cmd = _unitOfWork.CreateCommand())
            cmd.CommandText = ".....";
            cmd.AddParameter("id", account.Id);
            // [...]

To make it work you need to configure the UnitOfWorkFactory:

public static void Main(string[] argv)


public IUnitOfWork Create()
    var conString = ConfigurationManager
    var con = new SqlConnection(conString);

    //true = owns connection
    return new AdoNetUnitOfWork(con, true);