Hi All,
I’m having some issues trying to get Wirebox to inject a model from inside a model.
Basically, Model A does a call to Model B. All my models are by convention located in the new “models” folder. I have no issues injecting from a handler.
Inside of my config/Wirebox.cfc file I have my configure method set with the following mapping:
map(“correspondence”).to(“models.correspondence”);
I have no scope applied to this so it should be created as a “TRANSIENT” if my research is correct. As I did in my handlers I performed the annotation method:
property name=“correspondence” inject=“id:correspondence”; to match my alias set in the Wirebox binder or config file.
In my handlers i referenced it like so:
var objCorrespondence = getInstance(“correspondence”);
Everything works fine there.
In my model I get a slew of different responses:
if I leave the property annotation as stated earlier i get the following:
Injection Attempt 1 from Model A to Model B:
Annotation:
property name=“correspondence” inject=“id:correspondence”;
Call in the code:
var objCorrespondence = getInstance(“correspondence”);
Error Message Received:
Type: Injector.InstanceNotFoundException
Messages: Requested instance not found: ‘correspondence’ The instance could not be located in any declared scan location(s) () or full path location
Injection Attempt 2 from Model A to Model B:
Annotation:
property name=“correspondence” inject=“correspondence”;
Call in the code:
var objCorrespondence = getInstance(“correspondence”);
Removed the “id” in the annotation and added the “models” folder to the scanLocaions in config/Wirebox.cfc.
// Package scan locations
scanLocations = [“models”],
Reinited and I received the same error.
Injection Attempt 3 from Model A to Model B:
Annotation:
property name=“correspondence” inject=“correspondence”;
Call in the code:
var objCorrespondence = getInstance(“models.correspondence”);
Error Message Received:
Type: Expression
Messages: Variable GETINSTANCE is undefined.
Strangely, it says the Getintance method is not undefined now when I try using the direct model mapping.
Injection Attempt 4 from Model A to Model B: The last error lead to me to this. This method appears to be working.
Annotation:
property name=“correspondence” inject=“correspondence”;
Call in the code:
var objCorrespondence = application.wirebox.getInstance(“models.correspondence”); Is this now bypassing the annotation i have at the top of the model file.
Can anyone help me out on this? The model files are generally dumb in nature by design, i understand that piece. I just need some guidance if you could.
Referencing wirebox registered at the application level seems to work for me only if i go directly to the model listing and not through the alias I declared in the wirebox.cfc.
a little stuck. Also, is there a quick way to dump out all the aliases currently registered with Wirebox? ( Like the ones created asSingleton and asEagerInit(). )
Thanks!