I am experiencing an issue with v1 of Ninject and resetting the StandardKernel. I have a static object that I use to provide access to the kernel like so
public static class ObjectFactory
{
private static IKernel _kernel = new StandardKernel(new CanceisModule());
// Resolve methods snipped for brevity
public static void Reset()
{
_kernel = null;
_kernel = new StandardKernel(new CanceisModule());
}
}
The problem comes when I try to use ObjectFactory in various unit tests (I use MSTest) or fitnesse fixtures. I always call the ObjectFactory.Reset() method before every new test or fixture but sometimes it seems like the Reset doesn't actually work and leaves the original bindings in place. I know there is a way to reset the IKernel objects in v2 of Ninject but we aren't ready to make that move yet (and its a fairly significant move for us).
Could someone offer some advice on why this might be occuring? I'm guessing that it is related to the way tests are executed on separate threads in the different runners but how do I avoid it?
Thanks in advance