tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/36-some-questionsRobotlegs: Discussion 2013-04-28T10:02:52Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T10:35:14Z2010-01-26T10:35:14ZSome questions<div><p>Hi Camille,</p>
<p>I suppose by "init block" you mean the constructor, right? If
so,<br>
you've got three options:</p>
<p>1: Use constructor injection. If your class is created by the
injector<br>
- either because it is itself injected into some other class, or
because you're using injector.instantiate(MyClass) to instantiate
it -<br>
you can just add constructor arguments that then get supplied by
the<br>
injector.</p>
<p>2: Use the [PostConstruct] metadata annotation to let the
injector<br>
invoke a method of your class after all injections have been
applied.</p>
<p>3: Inject into a setter that then initializes you class.</p>
<p>You can find more documentation about all of these approaches in
the<br>
SwiftSuspenders README at<br>
<a href=
"http://github.com/tschneidereit/SwiftSuspenders">http://github.com/tschneidereit/SwiftSuspenders</a></p>
<p>cheers,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T12:06:13Z2010-01-26T12:06:16ZSome questions<div><p>Thanks a lot, I used the setter injection to initialize the
class!</p>
<p>Another question: I mapped a Command to be executed on an event
of class AEvent, but the same Command should be mapped to events of
class BEvent and CEvent, all subclassing flash.events.Event, yet if
I have an injectable property 'event' of type 'Event' I get
following error:</p>
<p><code>Error: Injector is missing a rule to handle injection into
target [object ErrorOccurred]. Target dependency:
flash.events::Event</code></p>
<p>Isn't it possible to let an injectable property accept instances
of subclasses?</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T12:15:33Z2010-01-26T12:15:33ZSome questions<div><p>Glad that worked out for you!</p>
<p>As for your events problem:<br>
While it is possible to map from one class in the injector to
another<br>
(i.e., the injector could be instructed to return an instance of
AEvent when asked for Event), it's unfortunately not possible
for<br>
Robotlegs to automatically set up these mappings.</p>
<p>The way the event injection works is by temporarily creating
an<br>
injector mapping for the event's class before instantiating the<br>
command and then removing that mapping afterwards.<br>
For you usecase to be supported, Robotlegs would have to create<br>
temporary mappings not only for the event's actual class, but also
for<br>
all its inherited classes - right up to Object.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T15:24:07Z2010-01-26T15:24:08ZSome questions<div><p>Ok, so that's just not possible. Guess I'll have to find a
(clean) work-around then.<br>
Just to make sure I understand correctly:<br>
for the injector there's no connection whatsoever between a class
and it's subclasses, right?</p>
<p>Coming back to the original problem, while it's easy enough to
solve, wouldn't it be better to have an automatically called
'onRegister' method for all Actor instances ? Just like in
mediators? Or is there a good reason not to do this?</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T15:26:00Z2010-01-26T15:26:01ZSome questions<div><p>And thanks for all the help BTW.<br>
RL really rocks!! It's my favorite AS framework by far and I've
been advertising it a lot!</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/9127362010-01-26T15:42:06Z2010-01-26T15:42:06ZSome questions<div><blockquote>
<p>for the injector there's no connection whatsoever between a
class and it's subclasses, right?</p>
</blockquote>
<p>Yes, that's correct. Everything else would have undesirable<br>
side-effects and be to heavy on performance.</p>
<blockquote>
<p>Coming back to the original problem, while it's easy enough to
solve, wouldn't it be better to have an automatically called
'onRegister' method for all Actor instances ? Just like in
mediators? Or is there a good reason not to do this?</p>
</blockquote>
<p>Basically, it's just not needed. You can achieve the exact
effect of<br>
Mediator's onRegister by using [PostConstruct]. The mediator
has<br>
onRegister to work around Flex's UIComponent taking some time to
be<br>
fully initialized.</p>
<blockquote>
<p>And thanks for all the help BTW. RL really rocks!! It's my
favorite AS framework by far and I've been advertising it a
lot!</p>
</blockquote>
<p>Yeah, Shaun has built something really great with Robotlegs.
It's<br>
awesome to see it taking off!</p></div>Till Schneidereit