injection into views

Chris Sheffield's Avatar

Chris Sheffield

18 Aug, 2010 04:05 PM

I sincerely apologize if this question has been addressed before. I couldn't find a specific reference to anything like this in my searching.

In my main context, I have the following code:

var selectedEmployee:Employee = new Employee();
injector.mapValue(Employee, selectedEmployee, "selectedEmployee");

Then, in a view, which consists of a form I'm using, I have this in a script block:

public var selectedEmployee:Employee;

The reason for injecting into the view is so that I can easily use 2-way data binding, but I'm wondering if this is the best way. Anyhow, with Robolegs 1.0.3, this works fine. But I recently tried updating to Robotlegs 1.1.2 and this broke for some reason. The selectedEmployee object ends up being null. I'm guessing something changed and I simply need to adjust, but I'm not sure how. Am I doing something wrong here? Why would it work with 1.0.3 but not 1.1.2? I have made no other change to my code except to swap out the swc's.

Any help would be greatly appreciated.


  1. 1 Posted by Nikos on 18 Aug, 2010 04:59 PM

    Nikos 's Avatar

    What version of swiftsuspenders are you using?

  2. Support Staff 2 Posted by Shaun Smith on 18 Aug, 2010 05:11 PM

    Shaun Smith's Avatar

    Probably the one the comes bundled with Robotlegs v1.1.2 (SwiftSuspenders 1.5.1).

    The behavior that you used to experience (injection into views that were mediated) was actually a bug with RL, and has been fixed. To regain this functionality you will need to explicitly inject dependencies into the view component. This can be done in the Mediator's onRegister() hook, like so:

    // First, inject the Injector into the Mediator
    [Inject] public var injector:IInjector;
    // Then, inside onRegister (assuming your view component is called "view"):

    Hope that helps!

  3. 3 Posted by Chris Sheffield on 18 Aug, 2010 05:24 PM

    Chris Sheffield's Avatar

    Yes! That did the trick. Thanks so much, Shaun.


  4. 4 Posted by Chris Sheffield on 18 Aug, 2010 05:34 PM

    Chris Sheffield's Avatar

    So I have to ask one more question. Is this kind of a hack or workaround to make this behavior work, or is this the proper way? Should I be going about this in some other way?


  5. Support Staff 5 Posted by Shaun Smith on 18 Aug, 2010 07:33 PM

    Shaun Smith's Avatar

    How does it feel to you? Does it feel hacky? I wouldn't worry too much about it to be honest. If it's working, and it doesn't make you want to tear your eyeballs out, then leave it. Later, if you decide it's hacky or high-maintenance, then look for another solution. That's my lazy answer, 'cos the real one would be too long :>

  6. 6 Posted by Chris Sheffield on 18 Aug, 2010 08:14 PM

    Chris Sheffield's Avatar

    Works for me. :-)

    Thanks again.

  7. Stray closed this discussion on 10 Feb, 2011 05:38 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