通用存储库 - IRepository 或 IRepository

10 浏览
0 Comments

通用存储库 - IRepository 或 IRepository

我看到了两种不同的创建通用存储库的方法。这两种方法之间有什么区别(优缺点)?

请忽略方法上的差异,因为我对以下两个方面的差异感兴趣:

 public interface IRepository where T : class

 public interface IRepository : IDisposable

在功能、灵活性、单元测试等方面有什么区别?我将会得到或失去什么?

它们在依赖注入框架中如何注册,有什么区别吗?

选项1

 public interface IRepository where T : class
{
      T Get(object id);
      void Attach(T entity);
      IQueryable GetAll();
      void Insert(T entity);
      void Delete(T entity);
      void SubmitChanges();
}

选项2

 public interface IRepository : IDisposable
   {
       IQueryable GetAll();
       void Delete(T entity);
       void Add(T entity);
       void SaveChanges();
       bool IsDisposed();
   }

0