tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/636-injectorinstantiate-and-injectormapsingleton-issueRobotlegs: Discussion 2012-08-30T15:20:24Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/183918012012-08-30T14:49:53Z2012-08-30T14:50:02Zinjector.instantiate() and injector.mapSingleton() issue.<div><p><code>injector.mapSingleton(AppModel); var appModel:AppModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel);</code></p>
<p>This code create 4 instancies. Is it a normal ? I thought it
create only one instance...</p></div>Pascaltag:robotlegs.tenderapp.com,2009-10-18:Comment/183918012012-08-30T15:12:15Z2012-08-30T15:12:15Zinjector.instantiate() and injector.mapSingleton() issue.<div><p>Hi Pascal,</p>
<p>The answer to your question is in here:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Internals">
https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...</a></p>
<ul>
<li>
<p>"instantiate" is used to create an instance of a given class,
regardless of whether or not there is a rule for such a class in
the container. As such, it must be handed a class, not an
interface, and it will always create a new instance. It is used by
the CommandMap to create new command instances.</p>
</li>
<li>
<p>"getInstance", on the other hand, can be handed a class,
abstract class, or interface, and it will return an instance based
on a previously mapped rule. As such, a rule must exist or an error
will be thrown. Also, multiple calls to "getInstance" might return
the same instance, whereas "instantiate" will always return a new
instance.</p>
</li>
</ul>
<p>hth<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/183918012012-08-30T15:18:56Z2012-08-30T15:19:00Zinjector.instantiate() and injector.mapSingleton() issue.<div><p>Ok, thanks Ondina !</p></div>Pascaltag:robotlegs.tenderapp.com,2009-10-18:Comment/183918012012-08-30T15:20:16Z2012-08-30T15:20:16Zinjector.instantiate() and injector.mapSingleton() issue.<div><p>My pleasure!</p></div>Ondina D.F.