From time to time, we have to make small changes to CFCs that are loaded as singletons on our production server. We don’t want to do a framework reinit on the production site, so what’s the simplest programmatic way to clear a particular singleton and have it reloaded?
Would it be something like:
wirebox.getScopes()[“SINGLETON”].getSingletons().remove(keyOfSingletonToRemove)
Has anybody implemented something like this? Or is there a better or more accepted way to do this on a production server?
TIA
Jamie
The injector has a method called clearSingletons() so just do
wirebox.clearSingletons();
I’ve never cleared a single singleton, but your code below will probably work.
However, PLEASE NOTE, that if you have injected a reference to your singleton into another CFC, that CFC will still keep its original reference.
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
"However, PLEASE NOTE, that if you have injected a reference to your singleton into another CFC, that CFC will still keep its original reference."
Is there a way to clear the references to the singletons that have been injected?
bdw429s
November 22, 2017, 12:27am
4
You could wrap every single injection in a provider.
property name=“myService” inject=“provider:myService”;
It’s a little messy but it would work because it asks WireBox for the instance every time.
Thanks!
~Brad
ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com