I want to bind IServiceProvider to Ninject IKernel implementation. What is the point to use
Bind<IKernel>().ToConstant(this).InTransientScope();
binding from Ninject sources ?
This is the way how Ninject bind IKernel to KernelBase implementation. I can't understand the point. ToConstant binding type set scope to Singleton implicitly. And TransientScope with ToConstant binding type does not give any sense to me.
ToConstant
has two primary effects:
Now the call to .InTransientScope()
after ToConstant
changes the scope from Singleton back to transient.
What does this change? "transient" objects will not be disposed by ninject. For Singleton
objects, if they're disposable, ninject will dispose them when the kernel is disposed. It's not doing that for "transient" objects.
So if the kernel would be bound .InSingletonScope()
, doing kernel.Dispose()
would result in another call to kernel.Dispose()
- maybe even a Stack Overflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With