假设有两个存储库接口:
interface IFooRepository
{
void Delete(int id);
}
interface IBarRepository
{
void Delete(int id);
}
还有一个 IUnitOfWork 接口,例如:
interface IUnitOfWork : IDisposable
{
void Commit();
void Rollback();
}
使用 ServiceStack.ORMLite 实现这些接口的最佳实践是什么,以便用户可以像使用它们一样
MyFooRepository.Delete(4);
// if an Exception throws here, Bar won't be deleted
MyBarRepository.Delete(7);
或者
using (var uow = CreateUnitOfWork())
{
MyFooRepository.Delete(4);
MyBarRepository.Delete(7);
uow.Commit(); //now they are in an transaction
}