tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/149-injection-into-viewsRobotlegs: Discussion 2018-10-18T16:35:15Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T16:05:01Z2010-08-18T16:05:01Zinjection into views<div><p>I sincerely apologize if this question has been addressed before. I couldn't find a specific reference to anything like this in my searching.</p>
<p>In my main context, I have the following code:</p>
<pre><code>var selectedEmployee:Employee = new Employee();
injector.mapValue(Employee, selectedEmployee, "selectedEmployee");</code></pre>
<p>Then, in a view, which consists of a form I'm using, I have this in a script block:</p>
<pre><code>[Inject(name="selectedEmployee")]
[Bindable]
public var selectedEmployee:Employee;</code></pre>
<p>The reason for injecting into the view is so that I can easily use 2-way data binding, but I'm wondering if this is the best way. Anyhow, with Robolegs 1.0.3, this works fine. But I recently tried updating to Robotlegs 1.1.2 and this broke for some reason. The selectedEmployee object ends up being null. I'm guessing something changed and I simply need to adjust, but I'm not sure how. Am I doing something wrong here? Why would it work with 1.0.3 but not 1.1.2? I have made no other change to my code except to swap out the swc's.</p>
<p>Any help would be greatly appreciated.</p>
<p>Thanks,<br />
Chris</p></div>Chris Sheffieldtag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T16:59:57Z2010-08-18T16:59:57Zinjection into views<div><p>What version of swiftsuspenders are you using?<br />
</p></div>Nikos tag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T17:11:47Z2010-08-18T17:11:47Zinjection into views<div><p>Probably the one the comes bundled with Robotlegs v1.1.2 (SwiftSuspenders 1.5.1).</p>
<p>The behavior that you used to experience (injection into views that were mediated) was actually a bug with RL, and has been fixed. To regain this functionality you will need to explicitly inject dependencies into the view component. This can be done in the Mediator's onRegister() hook, like so:</p>
<pre>
// First, inject the Injector into the Mediator
[Inject] public var injector:IInjector;
// Then, inside onRegister (assuming your view component is called "view"):
injector.injectInto(view);
</pre>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T17:24:36Z2010-08-18T17:24:36Zinjection into views<div><p>Yes! That did the trick. Thanks so much, Shaun.</p>
<p>Chris</p></div>Chris Sheffieldtag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T17:34:50Z2010-08-18T17:34:53Zinjection into views<div><p>So I have to ask one more question. Is this kind of a hack or workaround to make this behavior work, or is this the proper way? Should I be going about this in some other way?</p>
<p>Chris</p></div>Chris Sheffieldtag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T19:33:09Z2010-08-18T19:33:09Zinjection into views<div><p>How does it feel to you? Does it feel hacky? I wouldn't worry too much about it to be honest. If it's working, and it doesn't make you want to tear your eyeballs out, then leave it. Later, if you decide it's hacky or high-maintenance, then look for another solution. That's my lazy answer, 'cos the real one would be too long :></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/26198672010-08-18T20:14:55Z2010-08-18T20:14:56Zinjection into views<div><p>Works for me. :-)</p>
<p>Thanks again.</p></div>Chris Sheffield