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

Viewed 914

I want to use ninject (version 4.0.0) to resolve dependencies in my Windows Service program, I have seen quite a few tutorials, and they all use StandardKernel to initialize ninject Kernel as below:

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

But I am getting the following warning when using StandardKernel:

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

Can anyone give an example using StandardKernelConfiguration and StandardReadonlyKernel?

1 Answers

I had not realized that ninject version 4.0.0 is in beta, but the following syntax worked for me:

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