【发布时间】:2013-02-05 02:06:53
【问题描述】:
假设有两个repository接口:
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
}
【问题讨论】:
-
我建议尽可能避免使用 UOW。像这样传递一个开放的交易通常是一个非常糟糕的设计。 (在早期的修订中,我自己也犯了这件事)
标签: repository-pattern servicestack ormlite-servicestack