Signals and Injection Problem

jason.merrill's Avatar

jason.merrill

28 Apr, 2011 05:49 PM

Because of an error I am getting, I realized I am missing some understanding of how Robotlegs handles injected signals. I have seen Joel's examples of using Signals in Mediators. In that, he does no mapping of any signals in the context, and he injects signals into a view mediator. I am doing the same thing, and it works fine in one place and not the other. My Mediator is an extension made for Signals you've heard of called SignalMediator, but I wouldn't think that would make a difference. My error comes from swiftsuspenders and is:

Error: Injector is missing a rule to handle injection into property "userProfileRequestComplete" of object "[object MainViewMediator]"

userProfileRequestComplete is a Signal (an instance of a class that extends Signal). MainViewMediator is my class that extends SignalMediator, which is mapped in my Context to my MainView class. In that MainViewMediator, I am simply saying,

[Inject] public var userProfileRequestComplete:UserProfileRequestComplete;

So given that, I am confused for two reasons:

  1. Why the error.
  2. Why not the error? Meaning, how WOULD SwiftSuspenders know how to inject that signal if it had never been mapped before anyway? And confusing that, is Joel's example doesn't map any signals (other than mapping the signal to a Command, with SignalCommandMap, which I am also doing). I have another signal I am injecting the same way Joel did and that hasn't been throwing an error either - I can't see any real differences.

Any ideas on those two things above?

Thanks,

Jason

  1. Support Staff 1 Posted by Stray on 28 Apr, 2011 06:11 PM

    Stray's Avatar

    Hi Jason,

    when you say "other than mapping it in SignalCommandMap" - you've hit the nail on the head.

    The SignalCommandMap also takes care of mapSingleton for the signals it works with if they're mapped as Classes using mapSignalClass( )

    So - the simple solution is that all you need to do is create a 'Signalton':

    In your context:

    injector.mapSingleton(UserProfileRequestComplete);
    

    Hope that helps - come back if it's not clear,

    Stray

  2. 2 Posted by jason.merrill on 28 Apr, 2011 06:23 PM

    jason.merrill's Avatar

    OK thanks! That works.

    But what's confusing to me is why in Joel's SignalCommandMap example he doesn't do that (doesn't call the injector and mapSingletons of his Signal classes) and yet he injects them into mediators. And that's what I did to another signal as well - I never mapped a singleton of the signal class, and yet I was able to inject it into a mediator without any compiler errors.

    Should have mentioned my Context is a SignalContext not Context (like in Joel's example), but didn't think that was relevant.

    So why would it work in some places and not others? I don't see any differences between where it works and where it doesn't.

    The Joel Hooks example I am referring to is his Robotlegs Signals Café. He does not tell the injector to map any Signal class singletons in his context or anywhere else that I could see, yet he injects them.

     Jason Merrill
     Instructional Technology Architect
     Bank of America Global Learning

    _______________________

    -----Original Message-----
    From: Stray [mailto:[email blocked]]
    Sent: Thursday, April 28, 2011 2:11 PM
    To: Merrill, Jason
    Subject: Re: Signals and Injection Problem [Problems]

  3. 3 Posted by Stray on 28 Apr, 2011 06:35 PM

    Stray's Avatar

    If he's mapping them to commands, the signalCommandMap is mapping the singleton for him.

  4. 4 Posted by jason.merrill on 28 Apr, 2011 06:53 PM

    jason.merrill's Avatar

    He is, and so am I, hence why I didn't understand why the error.

     Jason Merrill
     Instructional Technology Architect
     Bank of America Global Learning

    _______________________

    -----Original Message-----
    From: Stray [mailto:[email blocked]]
    Sent: Thursday, April 28, 2011 2:35 PM
    To: Merrill, Jason
    Subject: Re: Signals and Injection Problem [Problems]

  5. 5 Posted by Stray on 28 Apr, 2011 07:50 PM

    Stray's Avatar

    That's strange Jason - can you post your code?

    It only maps as a singleton if you do mapSignalClass, not mapSignal ... so that would be strange.

    The other possibility is race conditions - could your mediator be being created before the signal mappings are completed?

  6. 6 Posted by jason.merrill on 28 Apr, 2011 07:53 PM

    jason.merrill's Avatar

    No, let me clarify, I was doing mapSignalClass on that Signal and I was still getting the injection error from SwiftSuspenders. The error went away when you had me do an injector.mapSingleton on the signal class.

     Jason Merrill
     Instructional Technology Architect
     Bank of America Global Learning

    _______________________

    -----Original Message-----
    From: Stray [mailto:[email blocked]]
    Sent: Thursday, April 28, 2011 3:50 PM
    To: Merrill, Jason
    Subject: Re: Signals and Injection Problem [Problems]

  7. 7 Posted by Stray on 28 Apr, 2011 08:33 PM

    Stray's Avatar

    In that case, could you post your code sample? I'd like to check it against the unit tests as that's not (afaik) the intended behaviour - though I think it could be a child-injector / parent-injector issue, but I'd need a code sample to be able to tell. You can use pseudo classnames, as long as it's exactly as you had it (including the mediator mapping for that mediator)

    The risk is that you're injecting a different singleton instance into the mediator to the one that the signalCommandMap is wired to...

    Stray

  8. 8 Posted by kevinkorngut on 06 May, 2011 09:17 PM

    kevinkorngut's Avatar

    I ran into the missing rule to handle injection to target error when my signal was dispatching a variable which I hadn't actually initialized. My mistake of course, I just hadn't expected SwiftSuspenders to notify me in that way.

  9. Support Staff 9 Posted by Stray on 11 May, 2011 08:39 AM

    Stray's Avatar

    Hi Jason - did you get anywhere with this?

    Our tests show that SignalCommandMap does do the injection for you.

    The only other thing I wondered is whether you're doing something funky when you create the SCM which isn't hooking up the parent/child injectors.

    Stray

  10. 10 Posted by jason.merrill on 12 May, 2011 04:06 PM

    jason.merrill's Avatar

    Hey thanks for the follow up! I've been very busy, thanks for all your help. I'll try out a test today and get back to you. If I recall, I got this working but need to confirm, thanks,

     Jason Merrill
     Instructional Technology Architect
     Bank of America Global Learning

    _______________________

  11. 11 Posted by jason.merrill on 17 May, 2011 07:15 PM

    jason.merrill's Avatar

    My project has changed significantly since I started this thread - I don't know heads or tails what I was doing then, but I have the original problem fixed so I'll close this thread for now. I'm not sure what I did to get the error, and I can't seem to replicate it now. Thanks for all your help!

  12. jason.merrill closed this discussion on 17 May, 2011 07:15 PM.

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