tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/41-errorinjector-is-missing-a-rule-to-handle-injection-into-targetRobotlegs: Discussion 2018-10-18T16:35:08Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/9831322010-02-07T09:24:27Z2010-02-10T05:45:36ZError:Injector is missing a rule to handle injection into target<div><p>I saw that there was a thread about this previously, but I am
pretty sure there is a bug in v1.03 with injector.mapSingleton( foo
)<br>
In previous releases I was able to map a singleton without issue,
but now I am getting the missing rule error.</p>
<p>in the Context startup method I have this:<br></p>
<pre>
<code>injector.mapSingleton(TestModel);</code>
</pre>
<p>TestModel is this:<br></p>
<pre>
<code>public class TestModel extends Actor
{
/**
* @constructor
*/
public function TestModel()
{
trace("TestModel::TestModel()");
super();
}
}</code>
</pre>
<p>Trying to use it like this:<br></p>
<pre>
<code>public class ApplicationMediator extends Mediator
{
[Inject] public var model:TestModel;
override public function onRegister():void
{
trace("ApplicationMediator::onRegister()");
}
}</code>
</pre>
<p>Throws an error every time.</p></div>kristoferjosephtag:robotlegs.tenderapp.com,2009-10-18:Comment/9831322010-02-07T09:29:29Z2010-02-07T09:29:33ZError:Injector is missing a rule to handle injection into target<div><p>I figured it out.<br>
It was an order of operation issue.<br>
It seems you need to map the singleton before your mediator
mappings.<br>
Otherwise there is a race condition where the mediator is created
before the model is instantiated.<br>
The error message is just misleading.</p></div>kristoferjosephtag:robotlegs.tenderapp.com,2009-10-18:Comment/9831322010-02-07T11:57:15Z2010-02-07T11:57:15ZError:Injector is missing a rule to handle injection into target<div><p>I guess you're probably mediating the contextView in addition to
other<br>
views, right? If so, that's what is causing what you're seeing:<br>
The MediatorMap has a special case for handling the contextView<br>
(<a href=
"http://github.com/tschneidereit/robotlegs/blob/master/src/org/robotlegs/base/MediatorMap.as#L117">http://github.com/tschneidereit/robotlegs/blob/master/src/org/robot...</a>),
which causes the mediator for that to be created immediately
during<br>
the call to MediatorMap#mapView.<br>
In that case, the injector tries to inject into the
contextView's<br>
mediator and fails if you're only creating the injection rules<br>
afterwards.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/9831322010-02-07T23:22:19Z2010-02-07T23:22:19ZError:Injector is missing a rule to handle injection into target<div><p>Exactly. I must have missed the update that added the mapping
of<br>
context.</p>
<p>Kristofer</p></div>kristoferjoseph