Cannot use DI in component


If I do

<cfset VARIABLES.["#myObjectName#"]=CreateObject
<cfset VARIABLES["#myObjectName#"].doFunc()>


<cfcomponent name="myComponent" autowire="true">
<cfproperty name="oSession" type="coldbox:plugin:sessionstorage"

<cffunction name="doFunc">
<cfdump var="#variables.oSession#">

I get a Coldbox error "oSession is not found in Variables"

But if I do <cfproperty name="oSession"
type="coldbox:plugin:sessionstorage" scope="variables"> in the caling
cfc the dump of oSession shows the object, no error message

So I can't use this <cfproperty> in methods that get called from a
component but I can use it in the calling component.

Is this a bug in Coldbox or am I missing something?

I use cb 2.6.3, Coldfusion 8.0 on Win XP SP3


I’m not understanding what you’re trying to do, but this line…

<cfset VARIABLES.["#myObjectName#"]=CreateObject

… should throw an exception. If you are going to use array notation, you do not use the dot (.). So this line should be…

<cfset variables[myObjectName] = createObject(“component”,“myComponent”) />

Maybe that is causing your issue? I’m not sure, since I’m not understanding what it is you’re trying to achieve (other than DI).

The only way that your model objects can be autowired with dependencies is if you go through the coldbox’s getModel() method. If you are trying to create the object using createobject, you are doing it outside of the DI framework. Therefore, the errors.

I recommend the model integration guide.