2012-06-01 29 views
3

Ninject似乎有問題解決以下幾個:通用綁定在Ninject沒有默認構造

public interface IRepository<TEntity> : IDisposable where TEntity : class,IEntity 
{ 
} 

public class Repository<TEntity> : IRepository<TEntity> where TEntity : class,IEntity 
{ 
    protected IDbContext _context; 

    public Repository(IDbContext context) 
    { 
     _context = context; 
    } 
} 

當有必要做一些特別的東西,我做的:

public interface IMyEntityRepository : IRepository<MyEntity> 
{ 
    int GetSomeStuffForAnObject(); 
} 

這一工程很好,但綁定不起作用,如果我只使用默認Repository<T>

+0

Bind(typeof(IRepository <>))。(typeof(Repository <>)); – bhaydin

+0

請使用標記行下的_「edit」_鏈接來編輯您的問題並放入您的評論代碼(我不知道該放哪裏) –

回答

1

好的,我一定錯過了一些東西。

Bind(typeof(IRepository<>)).To(typeof(Repository<>)); 

似乎工作。

相關問題