tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/1385-null-eventdispatcher-in-modelRobotlegs: Discussion 2013-04-08T15:45:00Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/262763242013-04-08T03:20:08Z2013-04-08T03:20:10ZNull eventDispatcher in Model<div><p>I've simplified it down to the following in my config file:</p>
<pre>
<code>context.injector.map(SphereModel).toValue( new SphereModel() );</code>
</pre>
<p>I see the super being called only once, but when setActivePoint
is called in a different command class, eventDispatcher is still
null</p></div>John Ptag:robotlegs.tenderapp.com,2009-10-18:Comment/262763242013-04-08T07:29:06Z2013-04-08T07:29:06ZNull eventDispatcher in Model<div><p>Hello John,</p>
<p>That’s because you are instantiating the model
yourself:<br>
var _model:SphereModel = new SphereModel();</p>
<p>You need to let the injector create an instance of a class that
requires an injection.<br>
You can use one of the following mappings:</p>
<p>1.</p>
<pre>
<code>injector.map(AnotherModel).asSingleton();</code>
</pre>
<p>2.</p>
<pre>
<code>var anotherModel:AnotherModel = injector.instantiateUnmapped(AnotherModel);
injector.map(AnotherModel).toValue(anotherModel);</code>
</pre>
<p>3.</p>
<pre>
<code>var anotherModel:AnotherModel = new AnotherModel();
injector.map(AnotherModel).toValue(anotherModel);
injector.injectInto(anotherModel);</code>
</pre>
<p>4.</p>
<pre>
<code>var anotherModel:AnotherModel = injector.getOrCreateNewInstance(AnotherModel);
injector.map(AnotherModel).toValue(anotherModel);</code>
</pre>
<p>Does this help?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/262763242013-04-08T13:16:15Z2013-04-08T13:16:17ZNull eventDispatcher in Model<div><p>Thanks Ondina. That works great. I feel like i'm lacking on
information on how injection works. Is there documentation for
SwiftSuspsenders 2.0? Their wiki on github seems to be a bit
lacking.</p>
<p>I'll probably be back with more questions - RL seems to be a
great framework to standardize object communication.</p></div>John Ptag:robotlegs.tenderapp.com,2009-10-18:Comment/262763242013-04-08T15:44:58Z2013-04-08T15:44:58ZNull eventDispatcher in Model<div><p>No problem, John!</p>
<p>Hmm, you’re right, the SwiftSuspsenders 2.0 documentation
is not ideal.<br>
But since you’re using robotlegs 2, maybe you could walk
through its documentation on github and also through the examples
on this forum to learn how to use the injector for various
situations.<br>
And, of course, come back to the forum with questions, whenever you
need assistance!!!</p>
<p>rl2 start here:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p>and inspect every package to find the readme files..</p>
<p>I’m going to close this thread. You can reopen it, if need
be.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.