Translating Ninject to ASP.NET MVC 6 DI

前端 未结 2 902
情深已故
情深已故 2021-02-14 23:59

I am trying to get into the new ASP.NET MVC 6 stuff, but I\'m having a very hard time with their new DI system. I have tried to find resources online, but everything I find cove

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-15 00:19

    The AddTransient method has various overloads, one of which accepts a lambda expression:

    services.AddTransient(s => CreateDocumentStore());
    

    However it seems you are using the Ninject InSingletonScope() modifier so this may be more appropriate:

    services.AddSingleton(s => CreateDocumentStore());
    

    Additional note: There is some pre-release documentation available (of course, it's not complete and may be incorrect but may help)

提交回复
热议问题