WireBox: Something like onTearDown() for scoped objects?


I’m still an entry-level user where WireBox is concerned, but is there any way to specify a kind of cleanup method if an object that has been scoped using

*".into(this.SCOPES.REQUEST)"* or the session/application equivalent?

Basically, something like a way to provide the name of a method that's to be called during onApplicationEnd() in case of an application-scoped object. Even better if it's just a convention for a method name to be used.
In the case of a wrapper for a non-standard protocol library (in my case for a heavily customized Java FTP client) this would be used for things like gracefully closing a connection so the other side doesn't have to wait until it can time it out or to re-establish it if some of the connection properties are supposed to differ after a framework re-init.

I could just work this into the regular application life cycle methods, but that just doesn't seem as clean.

Hope this will make enough sense to warrant a reply.
Thanks in advance!

Best regards,

ColdFusion doesn’t supply any form of finalizers and not all native CF scopes announce their demise to WireBox, so in short your answer is no. Now, that being said, you could probably get creative to cover most of your scenarios.

The biggest issue is that objects that are scoped in native CF scopes fall “out of scope” on their own without WireBox doing anything or knowing about it. Therefore there’s no programmatic way to have WireBox do anything when the scope dies. Your best bet are the onRequestEnd, onSessionEnd, and onApplicationEnd methods in Application.cfc. The good thing is, if your Application.cfc is setup correctly, those should automatically fire your postProcess, sessionEnd, and applicationEnd interception points. (And technically postProcess is NOT tied to onRequestEnd) You can write an interceptor that listens one each of those events, retrieves each item from the corresponding WireBox scope, and calls your finalization method.

In addition, if the WireBox injector is shutdown (like during a reinit), you’ll want to listen to the beforeInjectorShutdown interception point, and finalize all objects. Note, this will only work on application as the “sessIon” scope will only be the session of the request shutting down the injector and not all sessions.

This is an interesting behavior that would be handy to have baked into WireBox, but it faces issues as we couldn’t always guarantee the finalizers to run since there’s no core construct in CFML for it. I put in the following ticket to look at the possibility of enhancing WireBox: https://ortussolutions.atlassian.net/browse/WIREBOX-22



ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad

Thanks for your reply!

Yes, I mentioned those scopes because the basics for those events are already there and it’s just a question of whether or not the necessary infrastructure built on top of that was as well and I was maybe just not aware of it.

The regular interception points are a possible workaround for that, but I’m sure you can see how that’s not exactly ideal.
Think of something like that protocol wrapper mentioned above, which establishes a connection during its init() and would therefore (if it’s not yet been injected for use in its intended service locations) establish its connection in the interceptor just to immediately close it again. That can obviously be worked around in some cases, but it’s not the best way imaginable.

BTW: In case you haven’t already come across it you might also be interested in Steven Neiland’s feature suggestion for related engine-level events:

Thanks again and also for mentioning the necessary interception points to look into.

Best regards,