[coldbox-3.1.0] - Issues with wirebox injection

I am attempting to map a service in my wirebox configuration… passing in a reference to my DAO in the arguments.

Can you explain some interesting things that are happening

Here is my config

map(“PillarDAO”).to(“modules.mymodule.model.PillarDAO”)
.asSingleton();
map(“PillarService”).to(“modules.mymodule.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

In my handler I have tried using a property

property name=“objPillarService” inject=“PillarService”;

But with no luck I have reverted to getting the service directly out of the wirebox application instance.

variables.objPillarService = application.wirebox.getInstance(‘PillarService’);

Now in this last example i am geting an error saying

Error Messages: Error building: crown.modules.mymodule.handlers.MyHandler-> Error building: PillarService -> The PILLARDAO parameter to the init function is required but was not

I was then thinking that perhaps since I have made some changes I needed to reinit my app… so I added in fwReinit and init_app

But still the same error.

Now here comes the strange part

I completely removed the mappings of both the DAO and the Service from my wirebox config… And I still get the error!
How can it be even finding my PillarService if there is no mapping setup?

Perhaps my wirebox is not reinitialising for some reason?

Thanks guys

Also… I have had some strange things going on with my cfbuilder… It creates sub directories in my model folders for CVS
e.g. CVS/Base/MyDAO.cfc

And in some instance coldbox has been finding these files instead of the the components in my actual model folder… almost as if it is scanning sub directories first!

Thanks for any pointers in advance

Alex

Update

I have added a new mapping called PillarServiceTest.

so

map(“PillarDAO”).to(“modules.mymodule.model.PillarDAO”)
.asSingleton();
map(“PillarService”).to(“modules.mymodule.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

Now when I do

variables.objPillarService = application.wirebox.getInstance(‘PillarServiceTest’);

in my Service… It works just fine!

It’s almost as if because I have called my mapping the same name as the service it is ignoring the mapping and instead scanning the directory structure?

Thanks again in advance!

Sorry was meant to read for my config example

map(“PillarDAO”).to(“modules.mymodule.model.PillarDAO”)
.asSingleton();
map(“PillarServiceTest”).to(“modules.mymodule.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

Not sure why it would be still trying to use the mapping if you remove the map binding, the only thing I can think of is your have caching enabled of your handlers (which you should have on) so you might need to look into a reinit option for development.

Which is why you’re maybe getting the error in the first place, if it was setup without initArgs in the first place.

Got that turned off!!

But good to know we should have it on with a init var wrapped round it.

ta!

Yeah in development if you’re using singletons, there is a chance the data can be trashed with a reload of the handler, module etc. Especially if you rely on data being setup like this at run time. Now come to think of it that could be your problem, but I doubt it to be honest.

Can you try initWith and see if you get the same results, even though it should not matter. One allows you to define them individually while the other allows for a complete list of arguments to be sent.

Thanks… gave initWith a go… same error…

Going to give CF a reboot and see if that makes any difference…

Same error… Will keep digging and try to get to the bottom of it… thanks for your help!

try setting it up so the handlers and everything like modules etc are cached and see how you go.

Btw is this a ColdBox Module or ColdBox Application?

I found something similar on Google, which indicated that the wirebox configuration wasn’t getting loaded. And could you show us your config file in case there is something wrong there.

It is in a module

I just created a new “testService” thinking that something else was messing witht the “PillarService”

But the same thing happened there… strange thing is it works just fine aslong as I dont call the mapping the same as the service component name

so

map(“TestServiceTESTING”).to(“epsys.modules.green10.model.TestService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

Works

but

map(“TestService”).to(“epsys.modules.green10.model.TestService”) .initArg(name=“PillarDAO”,ref=“PillarDAO”) .asSingleton();

Causes the missing argument error!

This is our full wirebox config

its a bit of a mess as we are still in the development/research stage!

/*

And now our coldbox config

// Configure ColdBox Application function configure(){

// coldbox directives
coldbox = {
//Application Setup
appName = “Epsys”,

//Development Settings
debugMode = false,
debugPassword = “”,
reinitPassword = “”,
handlersIndexAutoReload = true,

//Implicit Events
defaultEvent = “”,
requestStartHandler = “”,
requestEndHandler = “”,
applicationStartHandler = “”,
applicationEndHandler = “”,
sessionStartHandler = “”,
sessionEndHandler = “”,
missingTemplateHandler = “”,

//Error/Exception Handling
exceptionHandler = “”,
onInvalidEvent = “”,
customErrorTemplate = “”,

//Application Aspects
handlerCaching = false,
eventCaching = false

};

//Wirebox
wirebox = {
enabled = true
//,singletonReload=true
,binder = ‘epsys.config.coldbox.WireBox’
};

layoutSettings = {
defaultLayout = “Main.cfm”
};

//Validation
validation = {
sharedConstraints = {
productListSearch = {
strSearch = {required=true}
}
}
};

//Interceptor Settings
interceptorSettings = {
throwOnInvalidStates = false,
customInterceptors = “”
};

//Register interceptors as an array, we need order
interceptors = [

];

}

Ok, if this is a module then you’re better off doing this in your module.config and not wirebox.

map(“PillarService@modulename”).to(“epsys.modules.green10.model.PillarService”)

Thanks… Moved over to my ModuleConfig.cfc

binder.map(“PillarDAO”).to(“epsys.modules.green10.model.PillarDAO”)
.asSingleton();

binder.map(“PillarService”).to(“epsys.modules.green10.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

binder.map(“PillarServiceTester”).to(“epsys.modules.green10.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

Unfortuantelly same issue… the PillarServiceTester mapping works fine

But the PillarService brings back an error when i try to inject it into my Handler with

variables.objPillarService = application.wirebox.getInstance(‘PillarService’);

But either way … makes much more sense for this to be in the module config!.. thanks!

Where are you using this?

Wirebox is built into ColdBox, so you wont need to do this

variables.objPillarService = application.wirebox.getInstance(‘PillarService’);

Just use getModel() instead or inject wirebox and use the getInstance()

Yes… I was injecting using property first… just tried using the application wirebox instance to try and circumnavigate any issues

but I suppose that won’t make any difference so will go back to injecting.

thanks

Yeah something doesn’t sound right, what you have is correct. Could you turn on logging and check the logs, you may need to change the min and max in logging to show more than warnings and info. But it maybe possible that something with the map and binding is not working right as what you have should be working.

Did you try

map(“PillarService@modulename”).to(“epsys.modules.green10.model.PillarService”)

notice the @ symbol!!

Heres the mappings in my Module

binder.map(“PillarDAO@green10”).to(“epsys.modules.green10.model.PillarDAO”)
.asSingleton();

binder.map(“PillarService@green10”).to(“epsys.modules.green10.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

binder.map(“PillarServiceTester”).to(“epsys.modules.green10.model.PillarService”)
.initArg(name=“PillarDAO”,ref=“PillarDAO”)
.asSingleton();

Then in my service I have added the property

property name=“objPillarService” inject=“PillarService”;

And the error I am getting is

The PILLARDAO parameter to the init function is required but was not passed in. with constructor arguments: {}

Will turn on the extra debugging and take a look

Thanks again

Ok I had to go looking into the binder stuff so this may not be correct Brad might have to pipe in.

But here is the problem that I see, first check that you are not setting up scanning of those folders for wirebox. Then if that looks right, it maybe that you’re right as it registers it by path name as well as DSL. It could be that it is finding the name via path and not by the DSL.

Now that brings me to another thing that you maybe doing wrong. As the code should maybe look like this

binder.map(“PillarService@green10”).to(“epsys.modules.green10.model.PillarService”)

.initArg(name=“PillarDAO”, DSL=“PillarDAO@green10”)
.asSingleton();

The ref I think is by ID and not DSL name, at least that is how I think it is working.

Btw… here is a stack trace

not sure if this helps

Tag Context:
ID: CFTHROW
LINE: 123
Template: C:\www\coldbox\system\ioc\Builder.cfc
ID: CF_TEMPLATEPROXY
LINE: 288
Template: C:\www\coldbox\system\ioc\Injector.cfc
ID: CF_TEMPLATEPROXY
LINE: 31
Template: C:\www\coldbox\system\ioc\scopes\NoScope.cfc
ID: CF_TEMPLATEPROXY
LINE: 261
Template: C:\www\coldbox\system\ioc\Injector.cfc
ID: CF_TEMPLATEPROXY
LINE: 476
Template: C:\www\coldbox\system\ioc\Builder.cfc
ID: CF_UDFMETHOD
LINE: 354
Template: C:\www\coldbox\system\ioc\Builder.cfc
ID: CF_TEMPLATEPROXY
LINE: 594
Template: C:\www\coldbox\system\ioc\Injector.cfc
ID: CF_UDFMETHOD
LINE: 481
Template: C:\www\coldbox\system\ioc\Injector.cfc
ID: CF_TEMPLATEPROXY
LINE: 33
Template: C:\www\coldbox\system\ioc\scopes\NoScope.cfc
ID: CF_TEMPLATEPROXY
LINE: 261
Template: C:\www\coldbox\system\ioc\Injector.cfc
ID: CF_TEMPLATEPROXY
LINE: 120
Template: C:\www\coldbox\system\web\services\HandlerService.cfc
ID: CF_UDFMETHOD
LINE: 141
Template: C:\www\coldbox\system\web\services\HandlerService.cfc
ID: CF_TEMPLATEPROXY
LINE: 550
Template: C:\www\coldbox\system\web\Controller.cfc
ID: CF_TEMPLATEPROXY
LINE: 236
Template: C:\www\coldbox\system\Coldbox.cfc
ID: CF_UDFMETHOD
LINE: 282
Template: C:\www\epsys\code\Application.cfc