Module Setting inside Model

Hello Guys,

I have the following component, but for some reason the property that should have the setting injected into it doesn’t ever appear to be set.

/*

  • This is an account service, which wil extend the coldbox virtual entity service.

*/

component extends=‘coldbox.system.orm.hibernate.VirtualEntityService’ {

// TODO: This might work, not sure I like injecting it as a property though, although, seems logical to me.

property name=“CustomAccountClass” inject=“coldbox:setting:account_class”;

public any function init(){

// Check to see if this custom account class property is defined in the configuration.

if (!isNull(CustomAccountClass)) {

// The application is using a custom extended account class.

// We need to init this service as the extended class.

super.init(CustomAccountClass);

} else {

// No custom class has been defined, so we’ll init using the standard class for the module.

super.init(‘Account’);

}

// Return this instance of the service.

return this;

}

}

I’ve used this injection method for settings in other parts of the application, both handlers and models and it appears to work perfectly, but not this time.

Any suggestions as to why? Or perhaps a work around?

Thanks,

Robert

If you are using it in the constructor, you need to inject it as an argument.

Curt Gratz

Computer Know How

Is it in a folder that is defined by the conventions? Any folder that is outside of the conventions or a child to such folders with conventions will not be auto wired.

Regards,

Andrew Scott

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

Yes, property mixins are injected after init().
So you have a few choices

  1. Pass it in as a constructor argument
  2. Leave it as is but create an onDIComplete() method that will post-process your data
  3. Create a method that does post processing for you (like above, but named whatever you like) and annotated with “onDIComplete”

Luis F. Majano
President
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

Hi Luis,

I’ve tried to do this using constructor argument injection, and still no dice, is this what you meant?

/*

  • This is an account service, which wil extend the coldbox virtual entity service.
    */
    component extends=‘coldbox.system.orm.hibernate.VirtualEntityService’ {

/*

  • We have to inject this setting as property injection isn’t done until after init().
  • @inject coldbox:setting:account_class
    */
    public any function init(AccountClass=‘Account’){
    // We need to init this service as the extended class.
    super.init(AccountClass);

// Return this instance of the service.
return this;
}

}

Thanks,

Robert

Almost, you need to tell it what to inject:

public any function init(AccountClass=‘Account’ inject=“coldbox:setting:AccountClass”){
// We need to init this service as the extended class.
super.init(AccountClass);

// Return this instance of the service.
return this;
}

Luis F. Majano
President
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

Hi Luis,

Sorry, but it doesn’t seem to like that syntax:

Error autowiring modules.saas.handlers.Accounts. invalid syntax in function head, missing ending [)]

Any idea?

Thanks mate,

Robert

Are yoau on 9 or 9.01

Luis Majano
President
Ortus Solutions, Corp
Toll free phone/fax: 1-888-557-8057
Mobile: 909-248-3408
www.ortussolutions.com
www.coldbox.org

Neither I’m on Railo :slight_smile:

Is that what’s causing the problem? Something we need to talk to them about?

I thought you could do metadata via arguments in railo. Yes, it is pretty much needed.

init(accountAccess=“default” inject=“coldbox:setting:AccountAccess”){}

Luis F. Majano
President
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

Hi Luis,

This appears to be a bug in script based components in Railo. I’ve opened a ticket with them.

Robert

Try the annotation approach

/**

  • @accountAccess.inject “coldbox:setting:AccountAccess”
    */
    function init(AccountAccess=“test”){}

Luis F. Majano
President
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

Hi Luis,

After spending some time on the bug tracker today it seems that Railo’s support for script based annotations is pretty weak no matter which way you approach it.

I’ve given them a poke to see if they can prioritise it, as both Wirebox and MXUnit rely on it for some great functionality.

Robert

Maybe you will need to get around it by doing a mapping in wirebox.

Where you define the constructor arguments there:

map(“alias”).initArg()

or
map(“alias”).initWith()

Luis F. Majano
President
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

For the moment I’ve just written the component in tag based syntax, I’ll convert it once Railo sort their bugs out, works just fine like that.

Thanks Luis,

Robert