tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/77-injection-into-command-doesnt-seem-to-be-workingRobotlegs: Discussion 2013-04-28T10:02:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/14049052010-04-08T16:01:11Z2010-04-08T16:01:16Zinjection into command doesn't seem to be working<div><p>Hello,</p>
<p>I'm sure I'm just doing something wrong. I'm still learning both
Flex and Robotlegs. So please be patient with me. :-)</p>
<p>In my context, I have this code:</p>
<pre>
<code>var selectedEmployee:Employee = new Employee();
injector.mapValue(Employee, selectedEmployee, "selectedEmployee");</code>
</pre>
<p>Then in my app's mediator I have this:</p>
<pre>
<code>[Inject(name="selectedEmployee")]
public var selectedEmployee:Employee;</code>
</pre>
<p>And then in an event handler, also in my app's mediator, I do
this:</p>
<pre>
<code>private function onSelectionChange(e:SelectEmployeeEvent):void
{
selectedEmployee = e.employee;
}</code>
</pre>
<p>All is well, and the selectedEmployee object gets set with the
properties and everything that it should. So now, at some point in
a command, I want to be able to access this exact same
selectedEmployee object. So in a command I have:</p>
<pre>
<code>[Inject(name="selectedEmployee")]
public var selectedEmployee:Employee;</code>
</pre>
<p>The command now has a selectedEmployee object, but it is not the
same instance as accessed in the app's mediator, as all of its
properties are null.</p>
<p>What am I doing wrong? Is this even the correct way to go about
things? From the examples in the Best Practices doc, it seems like
this should work. Any help would be appreciated.</p>
<p>Thanks,<br>
Chris</p></div>Chris Sheffieldtag:robotlegs.tenderapp.com,2009-10-18:Comment/14049052010-04-08T18:51:39Z2010-04-08T18:52:26Zinjection into command doesn't seem to be working<div><p>Hi Chris,</p>
<p>What's happening here is that the same instance IS being
injected into your Mediator and Command, BUT in the event handler
you are changing the Mediator's reference to point to a different
instance - doing so won't change any other references to the
original instance.</p>
<p>Instead of dealing with a single Employee instance you could
create an EmployeeModel that has a selectedEmployee property.
Inject the model into your Mediator and Command and manipulate the
selectedEmployee property as needed.</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/14049052010-04-08T19:31:54Z2010-04-08T19:31:54Zinjection into command doesn't seem to be working<div><p>Wow, Shaun. Thank you. I knew it would be something simple. And
it turned out to be my misunderstanding of assignments in Flex. :-)
I just assumed that I could copy one instance of an object into
another by using the assignment operator. Apparently that's not the
case. All is well now. Thanks again.</p></div>Chris Sheffieldtag:robotlegs.tenderapp.com,2009-10-18:Comment/14049052010-04-08T19:48:45Z2010-04-08T19:48:45Zinjection into command doesn't seem to be working<div><p>Cool, no problemo :)</p></div>Shaun Smith