I'm using Ninject (3.0) in my ASP.Net MVC3 project. At some point of request handling I want to execute some tasks.
I'm using session-per-request pattern but don't want these tasks to share the same Session as current Request has. So, I thought, ChildKernels could help me with this issue. I was going to create another binding for ISession in child kernel, but started with that:
var child = new Ninject.Extensions.ChildKernel.ChildKernel(NinjectMVC3.Kernel);
child.Dispose();
If I execute the code like that during request I get Error loading Ninject component ICache
exception at the end of my request (not at .Dispose()
call). If I remove child.Dispose()
everything is fine.
So, am I choosing the right way to go with ChildKernel? Is it safe to use the child kernels without explicitly disposing them? Why Ninject throws at the request end if I dispose the child kernel?