Ninject + Bind generic repository

前端 未结 2 1159
太阳男子
太阳男子 2020-12-01 11:35

I\'m trying to Bind a generic IRepository<> interface to my generic Repository<> - however it always return null?

I have tried various things like:

<         


        
相关标签:
2条回答
  • 2020-12-01 12:22

    See my answer on MVC3 Controller constructor + Ninject.

    Generic Binding works correctly in Ninject. Try using a parameterless constructor in Repository. I think the problem is there.

    0 讨论(0)
  • 2020-12-01 12:27
    Bind(typeof(IRepository<>)).To(typeof(Repository<>));
    

    This is the correct syntax for binding an open generic.

    If you are receiving null back when requesting IRepository< of whatever >, then there may be some other problem in an area of code you haven't shared.

    0 讨论(0)
提交回复
热议问题