Don’t abandon injection completely, just learn what is safe to inject. Any other objects that at are meant to be singletons (i.e. there is only one instance of that object that’s created and your entire application shares it) can be safely injected inside another singleton like your handlers. Singletons are usually handlers, services, DAO, interceptors. Of course, make sure are writing your singletons to be thread safe. This means var scoping all variables and being careful what you put in the this and variables scope.
There should be no problem injecting the following as long as they are thread safe:
> I actually thought I was using Wirebox to instantiate these models correctly
The WireBox binder config doesn’t instantiate anything. It simply stores the blueprint for how to make an object. The object is instantiated when it is inject, or any time getmodel() requests an instance.
For transient object-- these are objects that are created over and over again by your application and contain data specific to one user and their request. This of it this way, if 5 users hit the exact same page of your site at the exact same time and ran the exact same code, would you want them sharing the exact same user object with the same data between all 5 of them. The answer is most likely no, which is why you need to not inject the user, but ask WireBox for it every time and then keep it in a LOCAL variable so it doesn’t bleed over into anyone else’s request.
The cfproperty injections at the top of a component are only processed once when the CFC is first created. However, getModel() is ran every time and potentially returns a different object. As for your session behavior, it most likely is in a session somewhere, just not yours. Session scopes are unique to each user of your site. That includes any other devs, qa staff, and the load balancer ping that hits the server every 15 seconds. When an object is created, it is placed in the session that belongs to whatever user happens to be on the site and hitting the page that causes its creation. Chances are, you’re simply too slow and someone or something else is hitting the site first and causing the handler to be created, which is kicking off the one-time creation of the user object, and it is being persisted in their session, not yours.
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com