Injector is missing a rule to handle injection into target
Hi, I am building a modular application using robotlegs 1.5 and the utilities-modular library.
I've come up against a weird issue where I think I've set up a rule for an injection, but this fails at runtime.
Here is some code snippets showing the rule and injection, hopefully I've missed something obvious?
Context:
override public function startup():void{
//map view class type, required for correct injection of modules.
viewMap.mapType(IModule);
//mediatorMap
mediatorMap.mapView(MapAPIModuleShell, MapAPIModuleShellMediator);
//model
injector.mapSingleton(BoundingBox);
//commandMap
moduleCommandMap.mapEvent(BoundingBoxEvent.BOUNDING_BOX_IN_LAT_LONG, SaveBoundingBoxCommand);
Command and injection:
[Inject]
public var bbox:BoundingBox;
[Inject]
public var event:BoundingBoxEvent;
/**
* Handles saving bounding box to model object.
* TODO: handle metres.
* */
override public function execute():void{
if (event.type == BoundingBoxEvent.BOUNDING_BOX_IN_LAT_LONG){
bbox = event.boundingBox;
} else if (event.type == BoundingBoxEvent.BOUNDING_BOX_IN_METRES){
bbox = event.boundingBox;
}
//TODO: dispatch that the bounding box state has been saved
}
Here is the top of the stack trace:
Error: Injector is missing a rule to handle injection into target [class BoundingBox]. Target dependency: Number, method: constructor, parameter: 1
at org.swiftsuspenders.injectionpoints::MethodInjectionPoint/gatherParameterValues()[/Development/Projects/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/MethodInjectionPoint.as:110]
at org.swiftsuspenders.injectionpoints::ConstructorInjectionPoint/applyInjection()[/Development/Projects/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/ConstructorInjectionPoint.as:37]
at org.swiftsuspenders::Injector/instantiate()[/Development/Projects/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:138]
Any ideas?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Shaun Smith on 26 Apr, 2012 03:55 PM
Hello,
What does constructor of BoundingBox look like? The injector is saying that it doesn't know how to provide the first constructor argument of BoundingBox (which is a Number) when it tries to construct it.
Also, your command has a dependency on BoundingBox, yet it also maps BoundingBox as a singleton when it executes. Have you mapped the BoundingBox elsewhere, and are you intending to overwrite the mapping in the command?
3 Posted by jeremy.brooks on 26 Apr, 2012 03:58 PM
Just spotted that I left in the extra injection in the command, didn't mean to leave that in, I was experimenting, I've edited it now, thanks for the spot Shaun.
4 Posted by jeremy.brooks on 26 Apr, 2012 03:59 PM
The bounding box constructor looks like this;
5 Posted by jeremy.brooks on 26 Apr, 2012 04:06 PM
Shaun, you sparked an idea there, so instead of using mapsingleton I've used mapValue, providing a default object, worked great, thanks!
injector.mapValue(BoundingBox, new BoundingBox(0,0,0,0));
Support Staff 6 Posted by Shaun Smith on 26 Apr, 2012 04:09 PM
Aha, that's the problem right there :)
The injector has no idea how to create an instance of BoundingBox - it doesn't know how to provide any of the constructor arguments. You have a couple of options:
injector.mapValue(BoundingBox, new BoundingBox(7,5,90,90));Support Staff 7 Posted by Shaun Smith on 26 Apr, 2012 04:09 PM
You beat me to it :)
Shaun Smith closed this discussion on 26 Apr, 2012 04:09 PM.