小编Der*_*dik的帖子

使用通用存储库实现简单注入器

我在使用通用存储库实现 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)

c# generics dependency-injection simple-injector

1
推荐指数
1
解决办法
1493
查看次数