tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/5766-automagic-view-injectionRobotlegs: Discussion 2013-09-12T13:54:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/287580842013-09-12T10:32:12Z2013-09-12T10:32:12ZAutomagic view injection<div><p>Hello,</p>
<p>should views get injected automatically by default? Because on a
typicall setup when i put [Inject] tag into my view nothing
happens?</p>
<p>The readme.md states:</p>
<p><code>The view processor map provides automagic processing of
mapped views landing on the stage and manual processing where
preferred.</code></p>
<p>but my views get injected only when i explicitly call:</p>
<pre>
<code>viewProcessorMap.map(View).toInjection();</code>
</pre></div>jakub.gondektag:robotlegs.tenderapp.com,2009-10-18:Comment/287580842013-09-12T12:45:33Z2013-09-12T13:01:06ZAutomagic view injection<div><p>Hi Jakub,</p>
<p>Actually, there is no magic;)</p>
<p>The Injector "needs to know" how and where to provide
dependencies.</p>
<p>For an injection to occur there are 3 things needed:<br>
1-Injector - WHO (the Magician??)<br>
2-Injection point - [Inject] metadata - inside a class that needs
injection - WHERE<br>
3-Injector rule - mapping - WHAT + HOW</p>
<p>-------Injection rules--------</p>
<pre>
<code>Who ----------What--------How
injector.map (SomeClass).asSingleton();
viewProcessorMap.map(SomeView).toInjection();
mediatorMap.map(SomeView).toMediator(SomeMediator);
commandMap.map(SomeEvent.SOME_TYPE).toCommand(SomeCommand);</code>
</pre>
<p>-------Injection point--------</p>
<pre>
<code>public class SomeMediator
{
-------Where---------------What
[Inject]
public var someView: SomeView;</code>
</pre>
<p>-------Injection point--------</p>
<pre>
<code>SomeView
-------Where---------------What
[Inject]
public var someClass: SomeClass;</code>
</pre>
<p>Some rules are defined directly with the Injector - injector.map
(SomeClass).asSingleton();<br>
Some others by extensions like the MediatorMapExtension,
CommandMapExtension, ViewProcessorMapExtension, but they are making
use of the Injector as well.</p>
<p>A rule defined by the MediatorMap allows the Injector to inject
a View into its Mediator.<br>
Likewise, the ViewProcessorMap allows the Injector to inject
dependencies into Views, for example by inspection:<br>
viewProcessorMap.map(SomeView.toInjection();</p>
<p>Not all views landing on the stage are automatically processed!
Only the ones having a rule (mapping) will be passed to the
Injector, inspected and then injected with dependencies. An
injection point alone ([Inject]) won't suffice.</p>
<p>MediatorMap -->injection into Mediators<br>
ViewProcessorMap---> injection into Views</p>
<p>See this, too: <a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Internals">
https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...</a><br>
It's referring to rl1, but the general ideas are still valid.</p>
<p>I hope this will help.<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/287580842013-09-12T13:00:00Z2013-09-12T13:00:00ZAutomagic view injection<div><blockquote>
<p>The readme.md states:The view processor map provides automagic
processing of mapped views landing on the stage and manual
processing where preferred.but my views get injected only when i
explicitly call:viewProcessorMap.map(View).toInjection();</p>
</blockquote>
<p>I should have mentioned that when you create a context and
install an MVCSBundle, a couple of extensions will be installed,
but that doesn't mean that all of them will be automatically
functional. The MediatorMap won't "automagically" map your views to
their mediators. I guess the word "automagic" in the documentation
is misleading!<br>
So, if you need to map views to mediators, you'll have to
instantiate or have an injected IMediatorMap in your config class.
Same for the CommandMap and ViewProcessorMap, they have to be
explicitly instantiated and the used for mappings.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/287580842013-09-12T13:19:14Z2013-09-12T13:19:14ZAutomagic view injection<div><p>Hello,</p>
<p>thanks for the reply, an the second one too.</p>
<p>I know general rules for injection, but like you said was
misleaded by the<br>
word <code>automagic</code>.</p>
<p>Best regards<br>
Jakub Gondek</p></div>jakub.gondektag:robotlegs.tenderapp.com,2009-10-18:Comment/287580842013-09-12T13:54:33Z2013-09-12T13:54:33ZAutomagic view injection<div><blockquote>
<p>I know general rules for injection, but like you said was
misleaded by the word <code>automagic</code>.</p>
</blockquote>
<p>Yeah, sorry, I realized that after I wrote the first answer,
thus my second post:)</p></div>Ondina D.F.