Mapping Override error
Hi all,
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?
Here's my injection rule:
context.injector.map(IGameView).toSingleton(GameView);
Right below that I add the mediator mapping rule:
mediatorMap.map(IGameView).toMediator(GameViewMediator);
When I run it, I get this error:
Error: Injector mapping override for type [class IGameView]
with name at
robotlegs.bender.extensions.vigilance::VigilanceExtension/
I feel like I did this all the time in RL1.
Thanks!
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Shaun Smith on 03 Jan, 2013 10:53 AM
Hello,
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.
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
initialize
method:Hope that helps!
2 Posted by Smith Wilson on 03 Jan, 2013 05:18 PM
Thanks for the response Shaun.
So I definitely only want a single instance of IGameView. Without the injection rule though, how would it inject into the above example?
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?
I actually first tried to create the instance manually and use the toValue() but I got the same mapping override error.
Support Staff 3 Posted by Shaun Smith on 03 Jan, 2013 05:42 PM
Howdy,
That is how the mediator map works (and also why you're getting the error).
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
initialize
is called. The same is true for an event that triggers a command.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
initialize
is called the temporary mapping has been removed.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?
4 Posted by Smith Wilson on 03 Jan, 2013 06:34 PM
Thanks Shaun, I'm going to rework the structure.
Thanks again for all the amazing work! It's been incredibly valuable.
Support Staff 5 Posted by Shaun Smith on 03 Jan, 2013 06:42 PM
It's a pleasure! Good luck with the restructuring :)
Shaun Smith closed this discussion on 03 Jan, 2013 06:42 PM.