2012-01-25 38 views
1

我正在使用Ninject DI容器。和我有两个如何绑定具有约束条件的泛型类型

public interface IRepository<T> where T : AbstractEntity<T>, IAggregateRoot 
{ 
    // methods signatures 
} 

public class Repository<T> : IRepository<T> where T : AbstractEntity<T>, IAggregateRoot 
{ 
    // implementations 
} 

然后我试图将它们绑定在一个单独的模块

public class DataAccessModule : Ninject.Modules.NinjectModule 
{ 
    public override void Load() 
    { 
     this.Bind<IRepository<>>().To<Repository<>>(); 
    } 
} 

其中this.Bind<IRepository<>>().To<Repository<>>();不被识别为一个语句。

我该如何进行绑定?

+0

可能重复[NInject与通用接口](http://stackoverflow.com/questions/2216127/ninject-with-generic-interface) – nawfal

回答

5

here挂过这件作品。看起来像它为他们工作:

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