Passing an instance of a mediator

lukevanin's Avatar


14 Oct, 2011 08:23 AM

I'm migrating an application from an earlier version of RL, described here:

Using RobotLegs 1.5.1 and SwiftSuspenders 1.6.0 causes an error in the command:

Error while getting mapping response: No mapping defined for class xyz:InstallerMediator, named ""

The code currently maps a mediator to a view:

 mediatorMap.mapView(InstallerView, InstallerMediator, null, false, false);

It then attempts to inject this mediator into a command elsewhere, like this:

[Inject] public var installerMediator:InstallerMediator;

As far as I can tell the problem is either that there is no instance of InstallerMediator when the command tries to use it, or else the instance isn't mapped correctly.

In this forum post Shaun mentions mapping an instance of the mediator, like this,: injector.mapValue(MediatorClass, mediatorInstance), however since mapView only takes a Class and not an instance, I cannot see the connection to mapping this instance to a view.

  1. Support Staff 1 Posted by Till Schneidere... on 14 Oct, 2011 08:47 AM

    Till Schneidereit's Avatar

    Unfortunately, you've hit one of two known backwards-incompatible
    changes we made in 1.x point-releases of Robotlegs. Specifically, the
    MediatorMap used to create temporary mappings in the main injector to
    enable injecting the mediated view into arbitrary fields (or methods)
    of the mediator.

    The problem with that is twofold: It's sort of an implementation
    detail of the MediatorMap that wasn't intended to be exposed in the
    first place and it can cause pre-existing mappings of the same type to
    be overwritten. Imagine you had multiple instances of your
    InstallerMediator - how should the framework know which of those it
    should inject?

    This is why, when Swiftsuspenders gained support for child injectors,
    we changed the MediatorMap (as well as the other *Maps) to use their
    own internal child injectors for temporary mappings. Since, outside of
    these Maps, you don't have access to their injector, you can't inject
    the mediator anymore.

    The easiest way to quickly work around your issue is to map the
    mediator during its own initialization. I.e., in its onRegister

    If, on the other hand, you've got a bit more time on your hands, you
    should consider changing the architecture to not rely on mapped
    mediators at all. A mediator is supposed to only listen to framework
    events so that it can be removed automatically if and when its
    mediated view leaves the stage.

    hope that helps,

  2. 2 Posted by lukevanin on 14 Oct, 2011 08:58 AM

    lukevanin's Avatar

    Thank you. As you recommend I'm opting for changing the architecture from using commands which access the mediators, to handling events inside the mediators instead.

  3. Support Staff 3 Posted by Till Schneidere... on 14 Oct, 2011 08:59 AM

    Till Schneidereit's Avatar

    Cool, glad I could help

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