wirebox issue on legacy non coldbox code

Hi,

we have an app (partially) using coldbox but also (partially) running a legacy code base.
We want to use wirebox on the legacy part and so we defined in the application.cfc that onapplicationstart wirebox should be initiated

like this =>

//Load ColdBox application.cbBootstrap = CreateObject("component","coldbox.system.Coldbox").init(COLDBOX_CONFIG_FILE,COLDBOX_APP_ROOT_PATH,COLDBOX_APP_KEY,COLDBOX_APP_MAPPING); application.cbBootstrap.loadColdbox(); application.injector = createObject("component","coldbox.system.ioc.Injector").init(); return true;

then in some legacy page we try to use the injector like this=>

someModel = application.injector.getInstance(“modules.some.model.something”);

it fails on first attempt

# Element COLDBOXDSL is undefined in a Java object of type class [Ljava.lang.String;.

The error occurred in //something/coldbox/system/ioc/Builder.cfc: line 318
Called from //something/coldbox/system/ioc/Injector.cfc: line 594
Called from //something/coldbox/system/ioc/Injector.cfc: line 481
Called from //something/coldbox/system/ioc/scopes/CFScopes.cfc: line 58
Called from //something/coldbox/system/ioc/Injector.cfc: line 261
Called from //something/some.cfm: line 2
Called from //something/some.cfm: line 1
|


<br>316 : // ColdBox Context DSL<br>317 : case "ioc" : case "ocm" : case "webservice" : case "javaloader" : case "coldbox" : { <br>**318 : refLocal.dependency = instance.coldboxDSL.process(argumentCollection=arguments); break;** <br>319 : } <br><br>

|

but works after a refresh

any idea on what i should do to avoid this first attempt error?

Thanks for any help

Wirebox is part of Coldbox, so there is no need to set it up again.

Are you sure you are not trying to inject anything based on coldbox

As mentionned, the app is partially using coldbox
so everything goes through the same application.cfc but on requeststart if we are in some legacy cfm file we skip processing it as a coldbox request
so lines below are not executed
<cfset application.cbBootStrap.processColdBoxRequest()>
<cfset application.cbBootstrap.onRequestStart(arguments.targetPage)>

so we can say that its not linked to coldbox, i guess?

Yes, the exception you are getting is when an object is requesting another object from the ColdBox application eco-system. SO that was my question, are you reusing your entire object model?

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

What do you mean by are you reusing your entire object model?
if i do
try{
someModel = application.injector.getInstance(“modules.some.model.something”);

}
catch{
someModel = application.injector.getInstance(“modules.some.model.something”);

}

it works
so after failing once, it works
don’t understand why

Ok let me rephrase.

In your legacy app you are requesting an instance. However for some reason the exception is mentioning a dependency that requires ColdBox.this dependency can be a plugin, setting, etc.

That’s why I asked why? As the dependency is expecting a running ColdBox app. If that’s the case it means the app must be running so either it has to be bootstrapped or the dependency eliminated as you are in legacy mode.

As i mentionned,
this page is not processed as a coldbox request
because when it goes to the onrequeststart method, it’s detected to be a legacy file and both processColdBoxRequest() method is not exectued

below is how the application.cfc looks like
so the only thing there is that when it’s legacy code the following is not processed

<cfif( findNoCase(‘fw.cfm’,listLast(arguments.targetPage,"/")) ) and ( not findNoCase(‘index.cfm’,listLast(arguments.targetPage,"/")) )>
<cfset application.cbBootStrap.processColdBoxRequest()>

<cfset application.cbBootstrap.onRequestStart(arguments.targetPage)>

========>

//Load ColdBox application.cbBootstrap = CreateObject("component","coldbox.system.Coldbox").init(COLDBOX_CONFIG_FILE,COLDBOX_APP_ROOT_PATH,COLDBOX_APP_KEY,COLDBOX_APP_MAPPING); application.cbBootstrap.loadColdbox(); application.injector = createObject("component","wirebox.system.ioc.Injector").init(); return true;

<cfif not structKeyExists(application,“cbBootstrap”) or application.cbBootStrap.isfwReinit()>

<cfset structDelete(application,“cbBootStrap”)>
<cfset application.cbBootstrap = CreateObject(“component”,“coldbox.system.Coldbox”).init(COLDBOX_CONFIG_FILE,COLDBOX_APP_ROOT_PATH,COLDBOX_APP_KEY,COLDBOX_APP_MAPPING)>

<cfif( findNoCase(‘fw.cfm’,listLast(arguments.targetPage,"/")) ) and ( not findNoCase(‘index.cfm’,listLast(arguments.targetPage,"/")) )>
<cfset application.cbBootStrap.processColdBoxRequest()>

<cfset application.cbBootstrap.onRequestStart(arguments.targetPage)>

i still don’t get why it works on second attempt but anyway, what do you recommend to make it work?

I undersstand you are diverting the requests. I am not talking about the requests.

I am talking about your object model. The error you posted denoted that an objected requested a dependency that REQUIRED coldbox.

but the cfm file contains only this line failing

someModel = application.injector.getInstance(“modules.some.model.something”);
i abort it just after for testing purpose
so what else could it be requesting?

Ok, shows us the code for that model. But I am guessing that there is a DI being used in that model that is from a ColdBox application. The clue is that it is in the modules folder.

Couldn’t it also be that the model he’s injecting also has a dependency which requires Coldbox?

It’s odd that your path has “modules” in it. That is a Coldbox convention. You should be able to debug this one, just follow the trail of DI DSL in your model. Start with “modules.some.model.something”,

Jason, isn’t that exactly what I said!