"Reloading" Bindings in Ninject2?
- by Michael Stum
I'm using Ninject2 for DI and I have a Module that loads data from a config file.
I wonder if there is a way to tell the Kernel or the Module to reload the config? (I can trigger that through code if needed)
What worries me is the lifetime of existing objects. Say I have ITest bound to TestImpl1 in Singleton Scope and I change the config to bind ITest to TestImpl2 instead.
All new requests should get TestImpl2, but the classes that already requested TestImpl1 before obviously keep it. However, what if all users of TestImpl1 are gone - will TestImpl1 be properly garbage collected and disposed in case it implements IDisposable? Or will it just be orphaned?
Do I have to loop through each type and call Unbind/Bind on it? Or can I just unload the entire Module and reload it while still managing any existing object?