getWireBox instance call from onLoad in a module

Hi all,

I want to be able to call a service method from within the onLoad() function of my moduleConfig.
I came across this : http://wiki.coldbox.org/wiki/Modules.cfm#Interceptor_Methods:_onLoad().2C_onUnLoad().2C_etc that certainly suggests that I should be able to do this.
However, this returns that getModel() doesn’t exist.

A quick search of the google group turned up a post by Luis saying that I should be using controller.getWirebox().getInstance(“namehere”). When I try this I get :

The getFactory method was not found. |

  • |
    Either there are no methods with the specified method name and argument types or the getFactory method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity. |

The error occurred in D:\lib\coldbox310\system\plugins\IOC.cfc: line 130
Called from D:\lib\coldbox310\system\ioc\dsl\ColdBoxDSL.cfc: line 197
Called from D:\lib\coldbox310\system\ioc\dsl\ColdBoxDSL.cfc: line 37
Called from D:\lib\coldbox310\system\ioc\Builder.cfc: line 309
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 555
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 462
Called from D:\lib\coldbox310\system\ioc\scopes\NoScope.cfc: line 33
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 262
Called from D:\sites\namechanged\modules\staffboard\ModuleConfig.cfc: line 46
Called from D:\lib\coldbox310\system\web\services\ModuleService.cfc: line 321
Called from D:\lib\coldbox310\system\web\services\ModuleService.cfc: line 235
Called from D:\lib\coldbox310\system\web\services\LoaderService.cfc: line 89
Called from D:\lib\coldbox310\system\Coldbox.cfc: line 71
Called from D:\lib\coldbox310\system\Coldbox.cfc: line 102
Called from D:\sites\namechanged\www\Application.cfc: line 60 |

I also slightly naughtily tried controller.runEvent(), but that also throws a getFactory method not found, but with a different stack trace.

controller.getWirebox().containsInstance(“namehere”) returns true, suggestion I should be able to do this, but the getFactory method means nothing to me and I’m not really sure how to debug this or what other information I might be able to provide for folks to be able to help me…

Any help would be much appreciated.

Regards

Stephen

This should work.

var service = controller.getWirebox().getInstance(“wireboxIDOfService”);

I have it in the onLoad of many of my modules and it works fine.

Curt Gratz

Hi Curt,

That’s what I have as well…

In the config method I have :

binder.map(“StaffBoardService@staffboard”).to("#moduleMapping#.model.StaffBoardService");

In the onload I have:

var sbService = controller.getWireBox().getInstance(‘StaffBoardService@staffboard’);

and its the sbService = blah that is throwing the getFactory() error. :-/

I don’t need to extend the service off of anything do I?

Regards

Stephen

Hmm,

That should work. Curious, does this work…

var service = new#moduleMapping#.model.StaffBoardService”();

Heh well the service loads, but none of the methods work because it hasn’t been through the ColdBox injection services.

Stephen

Ya, like I said just curious.

Does the service work outside of onLoad()? Like if you inject it in a handler?

Curt

Yup.

I’m trying to add some functionality where I need to make sure some data is loaded when the module starts, that I didn’t previously need to load until an event was called.

Stephen

What version of coldbox is this?

3.1.0 - sorry. I didn’t state it explicitly as its in all the file paths.

Stephen

ahh I think what you are missing is the explicit enablement of WireBox. 3.1 had the compatibility one for cf7 that was turned on by default.

In your configuration file do this:

wirebox = {
enabled = true
};

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

Hmmm.

I have :

//WireBox Integration
wireBox = {
enabled = true,
//binder=“config.WireBox”,
singletonReload=true
};

In my coldbox config cfc. :frowning:

Stephen

Ok, the only thing it caught my eye, was that the stack trace is going back to the IOC plugin for some reason, that means that there is some injection point or something that references “IOC”

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

Well, we have ColdSpring for IOC, but its virtually unused…
The config looks like this :

ioc = {
framework = “coldspring”,
reload = false,
objectCaching = true,
definitionFile = “config/Coldspring.xml”
};

Its literally a standard coldbox coldspring xml file with 3 services defined in it from the application level. All the other services are defined using binder.map() in the modules.

Stephen

OK - so…

The service has these two injections at the top.

these beans are defined in the ColdSpring.xml file:

CEIntranet Transfer

Line 309 of the ioc/builder.cfc is trying to process the IOC properties in the service, which leads you up the stack trace to line 130 of the IOC plugin.

Is there something about the loading of modules and the onLoad method that means that the IOC config hasn’t been run through yet??

Regards

Stephen

Ahh ok, that explains it.

I would dish out using ColdSpring if you are already using WireBox. One less dependency to deal with.

The issue arises where the IOC container is not yet initialized, it happens after modules are online.

So you have two options:

  1. Migrate the 3 beans to wirebox
  2. Configure the IOC plugin manually: controller.getPlugin(“IOC”).configure();

If would go with number 1 and change your injections to:

or map them to abstract them

map(“Transfer”).toDSL(“cachebox:default:Transfer”);
map(“Datasource”).toDSL(“coldbox:datasource:CEIntranet”);

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

Cool! ColdSpring removed…

It was a bit scary replacing all the IOC references and I had a little bother with getting the application level models to load (I think that was mostly down to me typing single handed as my right wrist is currently healing from having had pins & plates put in.), but all looks good with existinf functionality.

I put my onLoad back in and got :

The DSL Definition {JAVACAST={null},NAME={Transfer},DSL={cachebox:default:Transfer},REQUIRED={false},SCOPE={variables},VALUE={null},REF={null}} did not produce any resulting dependency |

  • |
    The target requesting the dependency is: ‘StaffBoardService@staffboard’ |

The error occurred in D:\lib\coldbox310\system\core\util\Util.cfc: line 164
Called from D:\lib\coldbox310\system\ioc\Builder.cfc: line 348
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 555
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 462
Called from D:\lib\coldbox310\system\ioc\scopes\NoScope.cfc: line 33
Called from D:\lib\coldbox310\system\ioc\Injector.cfc: line 262
Called from D:\sites\ceintranet\modules\staffboard\ModuleConfig.cfc: line 43
|

Line 43 in ModuleConfig is my call to wirebox to get the service instance, which looks like this.

var sbService = controller.getWireBox().getInstance(‘StaffBoardService@staffboard’);

A few lines above in the configure() function the service mapped like so:

binder.map(“StaffBoardService@staffboard”).to(“#moduleMapping#.model.StaffBoardService”);

Transfer and my datasource are injected into the service like so :

and Transfer is configured as an interceptor like this in the coldbox.cfc:

{class=‘coldbox.system.orm.transfer.TransferLoader’,
properties = {
configPath = “/” & coldbox.appname & “/config/transfer.xml”,
definitionPath = “/” & coldbox.appname & “/definitions”,
datasourceAlias = ‘ceintranet’,
LoadBeanInjector = true,
BeanInjectorProperties = {
useSetterInjection =false,
debugMode = true
}
}
}

I’m guessing I’ve missed something, but I’m not sure what.

Any thoughts would be appreciated.

Thanks again.

Stephen

One question. What is putting transfer in cache?