This is giving me an error saying that OBJ_B does not have a valid constructor function. I’m assuming that this is because at this point they way it is coded OBJ_B has not been created yet in OBJ_A.
If I change the code to run to use another function that I call separately then it works fine.
`
component OBJ_A
output=“false”
accessors=true
{
property OBJ_B inject=“OBJ_B”;
property int someImportantNumber;
function init () {
return this;
}
function setImportNumber(){
setSomeImportantNumber(OBJ_B.getSomeImportantNumber());
}
}.
`
So my question comes down to is this the way it is suppose to work or do I have some configuration problem?
And or is there a different way to reference OBJ_B so that it is available to OBJ_A’s init function?
By putting the inject annotation on the property, Wirebox is only injecting OBJ_B after OBJ_A is intantiated. So when the init is called, there’s nothing being passed into the constructor so OBJ_B is not there yet.
What you want to do is inject into the constructor so it’s available at init time, here’s how:
@objB.inject OBJ_B
*/
public OBJ_A function init(required any objB)
{
// if you need to retain obj b within obj_a for use post init then set it into the property else obj b property defined above is not needed and you simply get the number value you are after into the some important number property.
setOBJ_B(objB);
setSomeImportantNumber(objB.getSomeImportantNumber());
}
}
Notice that now OBJ_B is being injected into the constructor method via the annotation “@objB.inject OBJ_B” and will now be available at init runtime.
Hope this helps,
Best of luck
Phill Nacelli
Sr. Software Architect, Solutions Lead
AboutWeb, LLC
You probably need to use OnDIComplete. The injected properties are not available at time of INIT() so you tell the INIT() function and wirebox that when the initialization of the the class is done, follow up with the OnDIComplete() function. I have to do this from time to time too.
function init () onDIComplete {
return this;
}
function OnDIComplete() {
setSomeImportantNumber(OBJ_B.getSomeImportantNumber());
}