Lazy<> Ninject Injection

后端 未结 3 705
余生分开走
余生分开走 2020-12-11 04:22

I use ninject framework. In my code I have a Lazy object. I can create an instance, but when I call the value property I got an exception.

 private La         


        
相关标签:
3条回答
  • 2020-12-11 04:30

    Use the factory extension for Ninject https://github.com/ninject/ninject.extensions.factory

    0 讨论(0)
  • 2020-12-11 04:32

    You need a default public constructor on Lazy :

    public Lazy() {}
    
    0 讨论(0)
  • 2020-12-11 04:48
    Bind(typeof (Lazy<IPsoriasisReportUserControl>)).ToMethod(
                ctx => new Lazy<IPsoriasisReportUserControl>(() =>
                      Kernel.Get<IPsoriasisReportUserControl>()));
    
    0 讨论(0)
提交回复
热议问题