[ColdBox-3.7.0] session scoped models

I have the following
main.cfc [singleton handler] → service.cfc [request coped model] → settings.cfc [session scoped model]

When I start my coldbox application for teh first time, and I dump out the entire session, I can’t find any reference to the settings model there.
When however, I load that same page again, the wirebox-injected settings model is present in the session scope.

In my main handler, I have an injection via cfproperty for the service; in the service I have a cfproperty injection for the settings model.

Am I wrong in thinking it would get injected in the session scope on my first request?
Is there any quick way to test why this isn’t being injected on my first request?
Can I inject it directly in my onsessionstart event, or is that bad practice?

Miakel,

What you are showing will cause scope widening injection. Meaning that you are creating memory leaks and bad references since you are injecting objects that are volatile. The request scoped and session scoped models should NOT be injected but requested or you can use our Provider pattern for this.

The reason is that those scopes will expire and your main.cfc references will be stale. You can read more about this in our WireBox page.

With that said, I would suggest either using providers or NOT injecting but requesting the objects from wirebox.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Luis,

Thank you for your fast reply, I appreciate it.

I see what you mean. I’ll delve further into the wirebox documentation.
Am I correct in assuming that this was causing the effect I saw?

best regards,
Mikaël

Yes, that would cause that affect. To request the items every time, inject WireBox into your handler and ask it for the transient any time you need it.

component singleton {
property name=“wirebox” inject=“wirebox”;

function index( event, rc, prc ) {
var shortLivedObject = wirebox.getInstance( ‘shortLivedObject’ );
shortLivedObject.doSomething();
}
}

To use the provider, inject like so

component singleton {
property name=“shortLivedObjectProvider” inject=“provider:shortLivedObject”;

function index( event, rc, prc ) {
shortLivedObjectProvider.doSomething();
}
}

This will not inject the real object, but a place holder object which provides it when needed. The provider uses onMissingMethod() to proxy method calls at run time. The provider also has a method called “get()” which will get the real object for you.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Holy cow! It works now!

At first I had skipped reading the details of wirebox, I had planned to do it later on, since it realy is a lot to digest. But man, it seems you can do a lot of wonderfull stuff with all that knowledge, so it really payed off to actually push through and read it all.
Even though I only needed to modify a few small details, a lot changed in how my dependencies are being treated, I like that. :slight_smile:
Seems I will be playing around with this some more…

Thanks for the assistance!
Mikaël