question about _wireme & autowire

I am trying to get coldbox to inject the property of a setting into a script component. I’ve included my code below. However, each time I call getMyFunction() it throws an error stating that getDatasource is null instead of my coldbox setting. It appears that _wireme and autowire isn’t being executed. Any ideas?

/**
*@accessors true
*@displayname User
*@output false
*@autowire true
*@hint A user object
*/
component
{
/

*@setter true
*/
property name=“datasource” type=“string” _wireme=‘coldbox:setting:myDatabaseSetting’;

public user function init()
{
return this;
}

public query function getMyFunction(numeric id)
{
var strSql = “SELECT * FROM data WHERE id = :id”;
var query = new Query();
query.setDatasource(getDatasource());
query.setSql(strSql);
query.addParam(name=“id”,value="#arguments.id#");

return query.execute().getResult();
}
}


Jeremy R. DeYoung
Phone: 615.261.8201

FacebookLinkedInGoogle ReaderTwitterAmazonGoogle
Google Talk/LunarFly Skype/DeYoungJD

Jeremy,

Try this instead

property name=“datasource” type=“string” inject=‘coldbox:setting:myDatabaseSetting’;

If you are on CB 3.0

Curt Gratz

Computer Know How

Curt, tried that as well. I’m using the latest github version of CB3.

Any other ideas?

I was able to wire a standard CFC using without any problem but I’m trying to force my self to use script versions b/c its much cleaner in my opinion.


Jeremy R. DeYoung
Phone: 615.261.8201

FacebookLinkedInGoogle ReaderTwitterAmazonGoogle
Google Talk/LunarFly Skype/DeYoungJD

Do you have autowiring turned on in your config file

interceptors = [

//Autowire

{class=“coldbox.system.interceptors.Autowire”,

properties={}

}

];

I tried what you had below and it worked for me with the inject notation.

Curt

I do however does it change anything if the model I’m trying to inject is within a module i.e.

/root/modules/mymodules/model/User.cfc

do I have to add the interceptor to the ModuleConfig.cfc as well?


Jeremy R. DeYoung
Phone: 615.261.8201

FacebookLinkedInGoogle ReaderTwitterAmazonGoogle
Google Talk/LunarFly Skype/DeYoungJD

Shouldn’t.

I double checked moving my test to a module and it still worked as expected.

I simplified it a bit, but it works for me. Is your myDatabaseSetting a simple string?

/**

*@accessors true

*@displayname User

*@output false

*@autowire true

*@hint A user object

**/

component

{

/*

*@setter true

*/

property name=“datasource” type=“string” inject=‘coldbox:setting:myDatabaseSetting’;

public any function init()

{

return this;

}

public any function getMyFunction(numeric id)

{

return getDatasource();

}

}

What version of ColdBox are you running?

Regards,

Andrew Scott

http://www.andyscott.id.au/

image001.jpg

I’m running CB3 latest github updates (rc2?) anyways, I copied and pasted the response from curt and it worked perfectly after that…very strange, I must have had a type-o.


Jeremy R. DeYoung
Phone: 615.261.8201

FacebookLinkedInGoogle ReaderTwitterAmazonGoogle
Google Talk/LunarFly Skype/DeYoungJD

Also, remember that when you add or change metadata, just must reinit for changes to take effect as metadata is cached for performance.

Luis F. Majano
President
Ortus Solutions, Corp

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