tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/3126-signals-startup-codeRobotlegs: Discussion 2013-06-14T12:39:13Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/273205232013-06-14T12:05:54Z2013-06-14T12:05:54ZSignals startup code<div><p>If I remember correctly, no injections in config files. But you
don't need them either, since you have access to the injector:</p>
<ol>
<li>Drop the <code>[Inject]</code> tag above
<code>initSignal</code><br></li>
<li>right before <code>context.afterInitializing(init)</code>
write<br>
<pre>
<code>initSignal = context.injector.getInstance(InitSignal);</code>
</pre></li>
</ol>
<p>et voila :)</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/273205232013-06-14T12:07:46Z2013-06-14T12:07:46ZSignals startup code<div><p>voila indeed, great!</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/273205232013-06-14T12:14:08Z2013-06-14T12:20:32ZSignals startup code<div><p>That’s right; the Injector can’t inject the signal
into your config class:<br>
no mapping == no injection</p>
<p>So, you have to find a way to map the signal before injecting
it.<br>
Maybe there are other solutions as well, but right now there are 2
ways of solving this that I can think of.</p>
<ul>
<li>You can have several config classes.</li>
</ul>
<p>CommandConfig, where you map your commands, MediatorsConfig,
where you map your mediators, and so on.</p>
<pre>
<code>context = new Context()
.install(MVCSBundle, SignalCommandMapExtension)
.configure(CommandsConfig)
.configure(ModelsConfig)
.configure(ServicesConfig)
.configure(MediatorsConfig)
.configure(AppConfig)
.configure(new ContextView(this));</code>
</pre>
<p>In your CommandConfig:</p>
<p>signalCommandMap.map( InitSignal ).toCommand( InitCommand );<br>
signalCommandMap.map( RequestTestSignal ).toCommand(
RequestTestCommand );</p>
<p>In your AppConfig (find a better name for it) you can now inject
the initSignal and dispatch it within your init method.</p>
<p>Note the order of your config classes: the config that maps the
signal has to run prior to the one you want to inject the signal
into.</p>
<ul>
<li>Instead of injecting it, you let the injector retrieve an
instance of your signal:</li>
</ul>
<p>(in your configure) signalCommandMap.map( InitSignal
).toCommand( InitCommand );</p>
<p>(in your init) var initSignal: InitSignal =
injector.getInstance(InitSignal);<br>
initSignal.dispatch();</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/273205232013-06-14T12:14:34Z2013-06-14T12:14:34ZSignals startup code<div><p>oops, late to the party;)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/273205232013-06-14T12:25:17Z2013-06-14T12:25:17ZSignals startup code<div><p>Late to the party, but more correct :)</p>
<p>I looked it up and Ondina's right, config instances <em>are</em>
injected with dependencies.<br>
But as she said, obviously you need to map a dependency first,
before it can be injected.</p></div>creynders