Hi Quintin
I'm also looking to do this but haven't settled on an approach yet for lack of time and some YAGNI.
Here is some code I haven't yet tested, but adapted from the open source SharpArch project. I like the interface alot, but I may have changed the NHib implementation a bit, as there are some things I don't love about SharpArch's repository implementation, but you can judge for yourself.
Of course using NHib session.BeginTransaction() introdues NHib dependencies, and not abstracting this out seems at odds with abstracting out IRepository and everything else. I for one would be very interested in what you conclude as a useful abstraction of transactions.
HTH,
Berryl
public interface IDbContext {
void CommitChanges();
IDisposable BeginTransaction();
void CommitTransaction();
void RollbackTransaction();
}
public class DbContext : IDbContext {
private readonly ISession _session;
public DbContext(ISession session)
{
Check.RequireNotNull<ISession>(session);
_session = session;
}
public void CommitChanges() { _session.Flush(); }
public IDisposable BeginTransaction() { return _session.BeginTransaction(); }
public void CommitTransaction() { _session.Transaction.Commit(); }
public void RollbackTransaction() { _session.Transaction.Rollback(); }
}