"Reloading" Bindings in Ninject2?
Posted
by Michael Stum
on Stack Overflow
See other posts from Stack Overflow
or by Michael Stum
Published on 2010-06-15T20:47:39Z
Indexed on
2010/06/15
20:52 UTC
Read the original article
Hit count: 201
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?
© Stack Overflow or respective owner