public class EfUnitOfWorkManager : IUnitOfWorkManager { private readonly DbContext _context; public EfUnitOfWorkManager(DbContext context) { _context = context; } public void Begin() { _context.Database.BeginTransaction(); } public void Commit() { _context.Database.CommitTransaction(); } public void Rollback() { _context.Database.RollbackTransaction(); } }
public class NhUnitOfWorkManager : IUnitOfWorkManager { private readonly ISession _session; public NhUnitOfWorkManager(ISession session) { _session = session; } public void Begin() { _session.BeginTransaction(); } public void Commit() { _session.Transaction.Commit(); } public void Rollback() { _session.Transaction.Rollback(); } }In this example, we are using the Begin, Commit, and Rollback methods to manage a transaction with the database through the NHibernate package library. The ISession object is passed into the constructor of the NhUnitOfWorkManager class and is used to interact with the database. Both of these examples demonstrate how the IUnitOfWorkManager interface can be used to manage the lifecycle of a unit of work when working with different package libraries in C#.