tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/182-broken-injector-or-im-doing-something-wrongRobotlegs: Discussion 2018-10-18T16:35:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/32213292010-10-04T20:46:00Z2013-08-30T15:47:09ZBroken injector or I'm doing something wrong<div><p>Here's a snippet, I put some additional trace statements to
verify if the Stage is really, really there.<br>
override public function startup():void { trace(contextView);
injector.mapValue(Stage, contextView);
trace(injector.getInstance(Stage)); // ... }</p>
<p>All return object Stage. It appears the injection simply doesn't
take place. Why is that?</p></div>archonttag:robotlegs.tenderapp.com,2009-10-18:Comment/32213292010-10-04T20:57:27Z2010-10-04T20:57:27ZBroken injector or I'm doing something wrong<div><p>Hi there,</p>
<p>You're creating the FullBrowserStageMediator in a conventional way - using new X() ... so it won't be injected into. Only classes which are instantiated by the framework (Commands, Mediators, classes mapped as Singletons etc) are automagically injected with their dependencies.</p>
<p>You could check out injector.instantiate()...</p>
<p>or even injector.injectInto(... )</p>
<p>Both of these would be helpful to you.</p>
<p>But - I'd say that this mediator should indeed be a mediator!</p>
<p>If you have FullBrowserStageMediator extend Mediator:</p>
<p>Then in your context do:</p>
<p>mediatorMap.mapView(ContextViewClass, FullBrowserStageMediator) /// I'm not sure what your ContextViewClass is - you should put that in here</p>
<p>and then instead of addressing the stage directly, do it via that contextView.</p>
<p>So you would have (in the FullBrowserStageMediator):</p>
<p>[Inject]
public var view:ContextViewClass;</p>
<p>and</p>
<p>override public function onRegister():void<br />
{</p>
<pre><code>view.stage.scaleMode = ... etc
// the code that is in your konstraktar function goes here</code></pre>
<p>}</p>
<p>If you don't have access to the stage from contextView then just pass in and mediate a view class that does have access to the stage.</p>
<p>It might even be possible to map to the Stage directly and use the mediatorMap.createMediator() function - as Stage is never added to the Stage :)</p>
<p>I'm not sure about mediating Stage directly - I've not tried it.</p>
<p>Hopefully this is enough to get you back on track,</p>
<p>Let us know if you need more guidance,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/32213292010-10-04T21:09:14Z2013-08-30T15:47:09ZBroken injector or I'm doing something wrong<div><p>That makes a lot more sense - I was under the impression that
injection works automatically. with all classes that use the tag.
You also helped me understand a (glaring) conceptual error that I
probably wouldn't have noticed.</p>
<p>I'll probably be using the injector.injectInto/instantiate
methods for non-MVC object factories, as a way to relatively
cleanly leverage SmartyPants in classes that won't use MVC but
could use dependancy injection.</p>
<p>Thanks for a very informative, valuable and concise post!</p></div>archonttag:robotlegs.tenderapp.com,2009-10-18:Comment/32213292010-10-04T21:24:33Z2010-10-04T21:24:33ZBroken injector or I'm doing something wrong<div><p>Awesome!</p>
<p>We aim to meet your injection needs. ;)</p>
<p>If you do try to mediate the Stage directly let us know how that goes - I should try it myself but I'm a bit short on time.</p>
<p>Cheers,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/32213292010-10-04T21:44:08Z2013-08-30T15:47:09ZBroken injector or I'm doing something wrong<div><p>Manually mediating the Stage works as you said.</p>
<pre>
<code> mediatorMap.mapView(Stage, FullBrowserStageMediator);
mediatorMap.createMediator(contextView);</code>
</pre>
<p>Apart from having to manually create a mediator, everything else
works as intended. I haven't tested for any potential problems with
events/signals, but I assume everything should work fine.</p></div>archont