Multiple mappings to a single mediator

Siddharth's Avatar


16 Jun, 2011 09:18 AM

Hi I wanted to know how would I go about achieving multiple mappings to a single mediator class ? If I use the following piece of code, I get an error that a rule has not been implemented for injection...

mediatorMap.mapView(RoboSample, ApplicationShellMediator);
mediatorMap.mapView('com.testpackage.modules.RoboModule1::RoboModule1', ApplicationShellMediator,IModule);

I basically want instance of RoboSample available inside ApplicationShellMediator and I also want an instance of RoboModule1 available inside ApplicationShellMediator. I have used the [inject] keyword for both variables but I get the above mentioned error.


  1. 1 Posted by Michal Wroblews... on 16 Jun, 2011 09:30 AM

    Michal Wroblewski's Avatar

    First of all check out that project which you can use to mediate subclasses of any given base class or even interface.

    Back to your problem. You always need to use the same class/interface for injectViewAs using one mediator. So both RoboSample and RoboModule should inherit from the same class or implements the same interface which you want to mediate.

    I hope it helps, if not let me know.

  2. 2 Posted by Stray on 16 Jun, 2011 09:30 AM

    Stray's Avatar


    The example you've given would try to mediate RoboSample and RoboModule1 each with their own Mediator - which is why you're getting the error.

    Robotlegs doesn't support the mixing of view injection and the mediator pattern as there is no need to mediate two views with the same mediator - you can use events to loosely couple two different mediators.

    A mediator isn't a view controller - so if you're putting logic in this mediator to facilitate some sort of collaboration between these two views that logic might be better done through a proper view controller.

    Alternatively you can access more views in one mediator by exposing them through parent views or through the contextView (which is injected into your mediator).

    Maybe if you can explain the purpose of the route you were trying to take then we can explain the 'normal' way of getting it done - Robotlegs is very flexible, but there are also some approaches that are guaranteed to not get you in trouble later, and others that are less optimal.


  3. 3 Posted by Siddharth on 16 Jun, 2011 09:37 AM

    Siddharth's Avatar

    hey thanks for the replies! What I was trying to do is that use the ApplicationShellMediator to listen to "events" dispatched by "modules" as well as function as a view mediator for the RoboSample view file. Basically I needed a reference to the context of the loaded RoboModule1 , for which I wanted its reference inside the Mediator.
    I have made a temperory workaround by creating a ModuleMediator which is solely responsible for module-shell communication and forwards events to other mediators.

    Is this alright ? Or is there a better alternative ?

    And also, could you show me how to map a mediator to multiple views ? I am not very clear about this.

    Thanks !!

  4. 4 Posted by Stray on 16 Jun, 2011 09:55 AM

    Stray's Avatar

    Hi Siddharth -

    Yup, the ModuleMediator-as-relayer approach is the one I favour. That's solid.

    As to how to map a mediator to multiple views - do you mean you want to use the same mediator class (but a different instance) for each of several view classes, or the same instance for multiple views? Robotlegs directly supports the first of those but not the second.


  5. 5 Posted by Michal Wroblews... on 16 Jun, 2011 10:02 AM

    Michal Wroblewski's Avatar

    As for mediating multiple views remember to use the same class/interface in injectViewAs parameter while mapping

  6. 6 Posted by Siddharth on 16 Jun, 2011 10:10 AM

    Siddharth's Avatar

    yes, I wanted to know about the second option...i.e. same instance... But in case that's not recommended I can try the other approach also.

  7. 7 Posted by Siddharth on 16 Jun, 2011 10:12 AM

    Siddharth's Avatar

    ok... i'll try with same interface for the injectViewAs param...

  8. Ondina D.F. closed this discussion on 02 Nov, 2011 05:55 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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