[coldbox-5.6.2] ensuring dependencies are loaded before a custom module onload() fires

How do I do this again? I have a dependency in a custom module in cbstorages and that modules is installed in the “root” application that houses my custom module. Is there someplace in the documentation that really describes building out and addressing dependency concerns ? I’m a little confused by it.


Should just be this in your moduleConfig.cfc

this.dependencies = [‘cbstorages’];


Doh…completely forgot about that.

So, I put that into my module configuration and it SEEMS to work, but when I put this…

function onLoad( event, interceptData, rc, prc ){
if (!wirebox.getInstance(“SessionStorage@cbstorages”).exists(“currentprojectspace”)) {
wirebox.getInstance(“SessionStorage@cbstorages”).set(“currentprojectspace”,456); // <— line 117 for example error below

(also tried afterAspectsLoad() ), the error tells me…

Element CBSTORAGE is undefined in SESSION.

The error occurred in /Users/mikecraig/repo/misc/modules/cbstorages/models/SessionStorage.cfc: line 117
Called from /Users/mikecraig/repo/misc/modules/cbstorages/models/SessionStorage.cfc: line 40
Called from /Users/mikecraig/repo/misc/modules_app/productadmin/ModuleConfig.cfc: line 116

I checked the sessionstorage cfc on that line of code and basically, it’s fail point starts at my call to set the value into session storage that I want and in the actual cfc, it first checks to see if cbstorage exists in session…if not, it creates it first then sets it…to which it is telling me that cbstorage does not exist in session.

if I drop a dump of the session scope inside that if clause first, I get an error saying variable session is undefined. Huh?

It seems that adding dependency correctly but after testing some, the problem is that even those the sessionstorage.cfc first creates session.cbstorage = {} before setting any variable to that structure, the session structure variable disappears and errors out saying session.cbstorage is not defined…and it isn’t…because session does not exist.

I’m pretty confused as this is a really simple example. I’ve removed any other related code chunks to my original problem so that I can simply make sure this variable I’m creating is stuffed into session.cbstorage

I’m a little baffled…certainly have used cbstorages many times before, just never done anything with modules onLoad()…but I still don’t see how these two problems are related.

Wow…I’m open to ideas.

Yeah…so while it seems that the dependency won’t get in the way, the session variable is not initialized by CF at that point…something that seems impossible to me. Clearly I’m doing something way wrong here. I’m going to start another thread to outline it better.

You need to include the full stack trace of these errors. I assume this is all happening as part of the onAplicationStart() method in your Application.cfc. Why are you trying to touch the session scope on app init anyway? That just doesn’t make sense.

Thanks Brad, that was helpful ! It was not actually my intention to touch any session-ish scope-y thing-ys in the application initialization process so as Jon walked me through some interesting alternative thinking we were able to resolve my issues and my thinking in a very elegant way.