问题
Is it right at all to "wrap" a StandardKernel
with the required NinjectModule
s in a static class in a separate, shared library, and use that same library whenever injection is needed (instead of instantiating a new kernel everytime)?
Edit: I am trying to use Ninject from within the WCF service I am developing at the moment.
(Please bear with me if what I am saying is completely rubish since I just started learning about DI and IoC containers)
回答1:
See https://github.com/ninject/ninject.extensions.wcf . This extension will create the WCF service using the Ninject kernel. That way you can use constructor injection instead of using the Service Locator pattern.
来源:https://stackoverflow.com/questions/7628365/ninject-kernel-in-static-class