tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/698-mapping-override-errorRobotlegs: Discussion 2013-01-12T12:49:08Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T06:17:50Z2013-01-03T06:17:51ZMapping Override error<div><p>Hi all,</p>
<p>Just started a new project with RL2. Really excited, but I'm
hitting the wall with something trivial. Can anyone point me in the
right direction?</p>
<p>Here's my injection rule:<br>
<code>context.injector.map(IGameView).toSingleton(GameView);</code></p>
<p>Right below that I add the mediator mapping rule:<br>
<code>mediatorMap.map(IGameView).toMediator(GameViewMediator);</code></p>
<p>When I run it, I get this error:<br>
<code>Error: Injector mapping override for type [class IGameView]
with name at
robotlegs.bender.extensions.vigilance::VigilanceExtension/</code></p>
<p>I feel like I did this all the time in RL1.</p>
<p>Thanks!</p></div>Smith Wilsontag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T10:53:46Z2013-01-03T10:53:46ZMapping Override error<div><p>Hello,</p>
<p>RL2 is a little more strict with that kind of thing. RL1 might
have allowed it, but it doesn't make sense to do that mapping
because any number of views might land on stage that implement that
interface.</p>
<p>If you're absolutely sure that there will only ever be one view
that implements that interface you can do the mapping in the
mediator's <code>initialize</code> method:</p>
<pre>
<code>[Inject]
public var injector:Injector;
[Inject]
public var view:IGameView;
public function initialize():void
{
injector.map(IGameView).toValue(view);
}</code>
</pre>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T17:18:20Z2013-01-03T17:18:20ZMapping Override error<div><p>Thanks for the response Shaun.</p>
<p>So I definitely only want a single instance of IGameView.
Without the injection rule though, how would it inject into the
above example?</p>
<p>I don't understand why the mediator map and injector are
mutually exclusive. I thought one describes how resources are
injected and the other describes how to associate a mediator?</p>
<p>I actually first tried to create the instance manually and use
the toValue() but I got the same mapping override error.</p></div>Smith Wilsontag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T17:42:04Z2013-01-03T17:42:04ZMapping Override error<div><p>Howdy,</p>
<blockquote>
<p>Without the injection rule though, how would it inject into the
above example?</p>
</blockquote>
<p>That is how the mediator map works (and also why you're getting
the error).</p>
<p>When a relevant view component lands on stage that view is
temporarily mapped for injection, the mediator is constructed and
injected into, the view is unmapped, and finally
<code>initialize</code> is called. The same is true for an event
that triggers a command.</p>
<p>The mapping override error happens because the mediator map is
trying to map the view component for injection - but you've already
mapped it. The work-around I mentioned above works because by the
time <code>initialize</code> is called the temporary mapping has
been removed.</p>
<p>With a typical MVCS application there should be no need to
inject the view component into anything other than its mediator. Do
you have a special use case that requires you to reference the view
from other parts of your system?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T18:34:05Z2013-01-03T18:34:06ZMapping Override error<div><p>Thanks Shaun, I'm going to rework the structure.</p>
<p>Thanks again for all the amazing work! It's been incredibly
valuable.</p></div>Smith Wilsontag:robotlegs.tenderapp.com,2009-10-18:Comment/234024052013-01-03T18:42:30Z2013-01-03T18:42:30ZMapping Override error<div><p>It's a pleasure! Good luck with the restructuring :)</p></div>Shaun Smith