RE: [coldbox:3271] Autowire and cfproperty

Try setting the debug param for the autowire interceptor to True, and
then watch the logs. That can help narrow down if the autowiring is
actually happening.

Also, what do you get if you cfdump out the instance scope after the CFC
has been initialized?

~Brad

Well, I went to edit the config and turn on Autowire debugging.
Something must have been cached because but changing the config to
turn debugging on, I started seeing the objects when dumping the
object. Here is a run-down of my play code.

In my General handler, I have the following:
  <cffunction name="testCFC" returntype="void" output="yes">
    <cfargument name="event" required="yes">
    <cfset var rc = event.getCollection()>

    <cfset var test = getModel("CarYearsDAO")>
    <cfdump var="#test#">
    <cfset event.noRender()>
  </cffunction>

In CarYearsDAO, I have:
<cfcomponent name="CarYearsDAO" extends="model.DAO" output="false"
cache="false" cacheTimeout="0">

  <cffunction name="init" access="public" output="false"
returntype="CarYearsDAO">
    <cfset super.init()>
    <cfreturn this>
  </cffunction>
</cfcomponent>

As you can see, CarYearsDAO extends DAO, and here is that code:
<cfcomponent name="DAO" output="false" autowire="true">
  <cfproperty name="dsn" type="coldbox.datasource.MegaSquirt"
scope="variables">
  <cfproperty name="cbController" type="coldbox" scope="variables">

  <cffunction name="init" access="public" output="false"
returntype="DAO">
    <cfset this.vars = variables>

    <cfreturn this>
  </cffunction>
</cfcomponent>

Here you can see the result of dumping my object in the General
handler:
http://megasquirt.cfcoding.com/index.cfm/General/testCFC

In the output, I see the "VARS" key and the value contains a structure
of dsn, cbController, and a few other things based on <cfset this.vars
= variables>, but when I try and call <cfset this.vars =
variables.dsn>, I get an undefined error... this isn't making much
sense to me as the dump is showing it's there.

Hi,

Try this
<cfcomponent name="DAO" output="false" autowire="true">
       <cfproperty name="dsn" type="coldbox.datasource.MegaSquirt"
scope="variables">
       <cfproperty name="cbController" type="coldbox"
scope="variables">

       <cffunction name="getCBController" access="public"
output="false" returntype="DAO">
               <cfreturn variables.cbController >
       </cffunction>
</cfcomponent>

getModel("DAO"). getCBController()

getModel() loads objects first then inject the dependencies. So its
mean you can use dependent objects are available in your methods for
further actions.

Again I would suggest to read model integration guide, there are more
ways to autowire as well.
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbModelGuide

Thanks

Well I followed your advice and I was able to get the injected objects
in my model to work in my controller. However, when I try to access
them within the model that they are being injected to, they are
undefined. And yes, I have read through the Model and Autowire guide
without any help there.

Here is something I found out today that seems very weird. Here is my
revised DAO. Notice that my injected objects are set to a scope of
"instance". However, in my getDSN() function, it returns the DSN
object from the variables scope. I am doing this because if I return
dsn from the instance scope, it's undefined.
<cfcomponent name="DAO" output="false" autowire="true">
  <cfproperty name="dsn" type="coldbox:datasource:MegaSquirt"
scope="instance">
  <cfproperty name="cbController" type="coldbox" scope="instance">

  <cffunction name="init" access="public" output="false"
returntype="DAO">
    <cfreturn this>
  </cffunction>

  <cffunction name="getDSN" access="public" output="false"
returntype="any">
    <cfreturn variables.dsn>
  </cffunction>

</cfcomponent>

And here is the code in my handler:
<cfset var test = getModel("DAO").getDSN()> // gets the DSN object
from the model
<cfdump var="#test#"> // dumps the DSN object
<cfdump var="#test.getName()#"> // dumps the name of the DSN

So, calling getDSN() from my handler works. It works as long as I
return the dsn object from "variables" and not from "instance" as I
declared in the cfproperty tag. Am I really not understanding this at
all, or could this be some sort of fluke?

Well, according to a source who has tried this on CF8 with ColdBox
2.x, it looks to be a bug with CF9 and the CB3.x beta as his code,
which is a direct copy of mine, works exactly as expected (being able
to access the injected object within the model itself). I guess I will
try to switch back to CF8 and the ColdBox final and see if it works
out.

Hi,

Ahh seems like a CF9 bug, because instance is in variables scope,
which is created by coldbox.
So its like this variables.instance = StructNew()
Then coldbox inject dependencies in instance variable.

This bug could be because of CF9 handles properties in variables scope
for getters/setters.

Thanks

Well it looks like that bug between variables and instance was a CF9
thing. However, I am still not having any luck. When I inject the DSN
object to my model, I can't use it within the model. I can only use it
within the handler that does getModel("MyDAO"). Am I mis-understanding
the use of this injection because from what I understand from the
documentation, it should work. If i inject the DSN to my model, why
would I want it to only be available in the handler? All of my data
access is within the DAO (obviously).

Let me clarify the getModel() behavior.

getModel("Name of component") actually injects your dependencies
automatically.
also getModel() is available in handler only.

For example in handler like this userService = getModel
("UserService")

userService.getSecurityObject( ...) in getSecurityObject method you
can access injected dependencies.

"For example you can do this getMyDsn() inside the getSecurityObject()
method"

Now you are talking about within model...? still not sure what exactly
you after.

Please provide more detail, if possible then some code sample.
We try to help you.

Thanks