我在使用通用存储库实现 SimpleInjector 时遇到一些问题。
我有一个接口和一个实现该接口的IRepository<T> where T : class抽象类。abstract class Repository<C, T> : IRepository<T> where T : class where C : DbContext最后,我有了继承抽象类的实体存储库。这是一个具体的例子:
public interface IRepository<T> where T : class
{
IQueryable<T> GetAll();
IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
void Add(T entity);
void Remove(T entity);
}
public abstract class Repository<C, T> : IRepository<T>
where T : class where C : DbContext, new()
{
private C _context = new C();
public C Context
{
get { return _context; }
set { …Run Code Online (Sandbox Code Playgroud)