Ninject-静态类中的内核? [英] Ninject - Kernel in static class?

查看:66
本文介绍了Ninject-静态类中的内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单独的共享库中的静态类中将"StandardKernel"与所需的NinjectModule包装"在一起,并在需要注入时使用同一库(而不是实例化新内核)是否完全正确?每次)?

Is it right at all to "wrap" a StandardKernel with the required NinjectModules 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)?

我正在尝试从目前正在开发的WCF服务中使用Ninject.

I am trying to use Ninject from within the WCF service I am developing at the moment.

(自从我刚开始学习DI和IoC容器以来,如果我所说的话完全是鲜红的,请与我包容)

(Please bear with me if what I am saying is completely rubish since I just started learning about DI and IoC containers)

推荐答案

请参见 https://github .com/ninject/ninject.extensions.wcf .该扩展将使用Ninject内核创建WCF服务.这样,您可以使用构造函数注入,而不是使用Service Locator模式.

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.

这篇关于Ninject-静态类中的内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆