How to bind Generic-type interfaces in Ninject

后端 未结 1 1181
不知归路
不知归路 2020-12-14 17:53

I\'m fairly new to Ninject, and found myself stumbling when I came to implement a generic repository pattern. I want to bind a dependency IRepository

相关标签:
1条回答
  • 2020-12-14 18:17
    kernel.Bind(typeof(IRepository<>)).To(typeof(SimpleRepository<>));
    

    Take a look at my one if you want here: http://blog.staticvoid.co.nz/2011/10/staticvoid-repository-pattern-nuget.html i have binding examples

    EDIT:

    The error you are getting is saying that your concrete repository isnt an instance of the generic one you want to bind to, ie you will need to do this

    public class ConcreteRepository<ConcreteEntity> : IRepository<IEntity>{}
    

    not

    public class ConcreteRepository<ConcreteEntity> : IRepository<ConcreteEntity>{}
    
    0 讨论(0)
提交回复
热议问题