c# - “标准内核”已过时 : `Use StandardKernelConfiguration and StandardReadonlyKernel`

标签 c# dependency-injection windows-services console-application ninject

我想使用ninject(版本4.0.0)来解决我的Windows服务程序中的依赖关系,我见过quite a few tutorials ,他们都使用 StandardKernel初始化ninject内核如下:

IKernel kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());

但是我在使用 StandardKernel 时收到以下警告:

'StandardKernel' is obsolete: 'Use StandardKernelConfiguration and StandardReadonlyKernel'



谁能举个例子,使用 StandardKernelConfigurationStandardReadonlyKernel ?

最佳答案

我没有意识到 ninject 版本 4.0.0 处于测试阶段,但以下语法对我有用:

IReadOnlyKernel kernel = new KernelConfiguration(new MyModule()).BuildReadonlyKernel(); 

关于c# - “标准内核”已过时 : `Use StandardKernelConfiguration and StandardReadonlyKernel` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60689012/

相关文章:

unit-testing - 在 golang 中模拟依赖项是否需要 DI(依赖项注入(inject))?

java - 使用依赖注入(inject)实现数据访问 API

.net-core - 当工作线程是事件驱动时,BackgroundService.ExecuteAsync 应该返回什么?

c# - 同步集合 : ReSharper "Implicitly captured closure"

c# - 在 Unity 中使用 IOptions

c# - 无法构建其中包含 processTemplate.xaml 的项目

windows-services - 更新Windows服务的过程?是自动的还是手动的?

vb6 - TreeView 控件 (comctl32.ocx) 不加载触摸屏服务

c# - IList<IClient> 方法<T>() 其中 T : Iclient can not add client object to list

c# - Windows 服务和 WCF Web 服务的 .NET 集中配置