tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/307-signals-and-injection-problemRobotlegs: Discussion 2018-10-18T16:35:26Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T17:49:08Z2011-04-28T17:49:08ZSignals and Injection Problem<div><p>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:</p>
<p><code>Error: Injector is missing a rule to handle injection into
property "userProfileRequestComplete" of object "[object
MainViewMediator]"</code></p>
<p>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,</p>
<p><code>[Inject] public var
userProfileRequestComplete:UserProfileRequestComplete;</code></p>
<p>So given that, I am confused for two reasons:</p>
<ol>
<li>Why the error.</li>
<li>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.</li>
</ol>
<p>Any ideas on those two things above?</p>
<p>Thanks,</p>
<p>Jason</p></div>jason.merrilltag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T18:11:23Z2011-04-28T18:11:23ZSignals and Injection Problem<div><p>Hi Jason,</p>
<p>when you say "other than mapping it in SignalCommandMap" -
you've hit the nail on the head.</p>
<p>The SignalCommandMap also takes care of mapSingleton for the
signals it works with if they're mapped as Classes using
<code>mapSignalClass( )</code></p>
<p>So - the simple solution is that all you need to do is create a
'Signalton':</p>
<p>In your context:</p>
<pre>
<code>injector.mapSingleton(UserProfileRequestComplete);</code>
</pre>
<p>Hope that helps - come back if it's not clear,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T18:23:58Z2011-04-28T18:23:58ZSignals and Injection Problem<div><p>OK thanks! That works.</p>
<p>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.</p>
<p>Should have mentioned my Context is a SignalContext not Context
(like in Joel's example), but didn't think that was relevant.</p>
<p>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.</p>
<p>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.</p>
<p>Jason Merrill Instructional Technology Architect Bank of America
Global Learning</p>
<p>_______________________</p>
<p>-----Original Message----- From: Stray [mailto:<a href=
"mailto:tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com">tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com</a>]<br>
Sent: Thursday, April 28, 2011 2:11 PM<br>
To: Merrill, Jason<br>
Subject: Re: Signals and Injection Problem [Problems]</p></div>jason.merrilltag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T18:35:09Z2011-04-28T18:35:09ZSignals and Injection Problem<div><p>If he's mapping them to commands, the signalCommandMap is
mapping the singleton for him.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T18:53:25Z2011-04-28T18:53:25ZSignals and Injection Problem<div><p>He is, and so am I, hence why I didn't understand why the
error.</p>
<p>Jason Merrill Instructional Technology Architect Bank of America
Global Learning</p>
<p>_______________________</p>
<p>-----Original Message----- From: Stray [mailto:<a href=
"mailto:tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com">tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com</a>]<br>
Sent: Thursday, April 28, 2011 2:35 PM<br>
To: Merrill, Jason<br>
Subject: Re: Signals and Injection Problem [Problems]</p></div>jason.merrilltag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T19:50:12Z2011-04-28T19:50:12ZSignals and Injection Problem<div><p>That's strange Jason - can you post your code?</p>
<p>It only maps as a singleton if you do mapSignalClass, not
mapSignal ... so that would be strange.</p>
<p>The other possibility is race conditions - could your mediator
be being created before the signal mappings are completed?</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T19:53:20Z2011-04-28T19:53:20ZSignals and Injection Problem<div><p>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.</p>
<p>Jason Merrill Instructional Technology Architect Bank of America
Global Learning</p>
<p>_______________________</p>
<p>-----Original Message----- From: Stray [mailto:<a href=
"mailto:tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com">tender+da6e99f38bc22fcfb6688945dcdbac295a84f53e6@tenderapp.com</a>]<br>
Sent: Thursday, April 28, 2011 3:50 PM<br>
To: Merrill, Jason<br>
Subject: Re: Signals and Injection Problem [Problems]</p></div>jason.merrilltag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-04-28T20:33:15Z2011-04-28T20:33:15ZSignals and Injection Problem<div><p>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)</p>
<p>The risk is that you're injecting a different singleton instance
into the mediator to the one that the signalCommandMap is wired
to...</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-05-06T21:17:40Z2011-05-06T21:17:42ZSignals and Injection Problem<div><p>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.</p></div>kevinkornguttag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-05-11T08:39:07Z2011-05-11T08:39:07ZSignals and Injection Problem<div><p>Hi Jason - did you get anywhere with this?</p>
<p>Our tests show that SignalCommandMap does do the injection for
you.</p>
<p>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.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-05-12T16:06:03Z2011-05-12T16:06:03ZSignals and Injection Problem<div><p>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,</p>
<p>Jason Merrill Instructional Technology Architect Bank of America
Global Learning</p>
<p>_______________________</p></div>jason.merrilltag:robotlegs.tenderapp.com,2009-10-18:Comment/68928212011-05-17T19:15:32Z2011-05-17T19:15:32ZSignals and Injection Problem<div><p>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!</p></div>jason.merrill