我试图从here了解工作单元和存储库模式。 它具有如下工作单元类
public interface IUnitOfWork : IDisposable
{
IRepository<TEntity> GetRepository<TEntity>() where TEntity : class;
int Commit();
}
public interface IUnitOfWork<TContext> : IUnitOfWork where TContext : DbContext
{
TContext Context { get; }
}
并通过类似的服务进行调用
public class SomeService
{
private readonly IUnitOfWork _uow;
public SomeService(IUnitOrWork unit )
{
_uow = unit;
}
public void SomeMethod(SomeClass entity)
{
_uow.GetRepository<SomeClass>().Add(entity);
_uow.Commit();
}
}
我对文章有疑问,如果有人可以详细说明。