“StandardKernel”已过时:请使用“StandardKernelConfiguration”和“StandardReadonlyKernel”。

5

我想使用Ninject(版本4.0.0)在我的Windows服务程序中解决依赖关系,我看过一些教程,它们使用 StandardKernel 来初始化Ninject Kernel,如下所示:

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

当我使用StandardKernel时,会收到以下警告:

'StandardKernel'已过时:请使用StandardKernelConfigurationStandardReadonlyKernel

是否有人可以举一个例子来使用StandardKernelConfigurationStandardReadonlyKernel


1
我仍在寻找一些具体的例子,但我倾向于检查测试以获取如何使用具有过时文档的库的示例。https://github.com/ninject/Ninject/blob/master/src/Ninject.Test/Unit/KernelConfigurationTests.cs - Nkosi
你使用的是哪个版本? - Nkosi
@Nkosi:感谢您的帮助...我刚刚注意到我错误地安装了处于beta阶段的ninject 4.0.0...我将回退到3.3.4(这是最新的稳定版本),看看是否会收到相同的警告。 - Hooman Bahreini
1
我也没有在仓库中找到那些类型。有KernelConfigurationReadonlyKernel - Nkosi
我回退到了3.3.4,警告消失了,但以下语法适用于版本4:IReadOnlyKernel readOnlyKernel = new KernelConfiguration(new SyncerModule()).BuildReadonlyKernel(); 已更新问题,对于引起的混乱表示抱歉。 - Hooman Bahreini
1个回答

2

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接