injector.instantiate() and injector.mapSingleton() issue.
injector.mapSingleton(AppModel); var appModel:AppModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel); appModel =
injector.instantiate(AppModel);
This code create 4 instancies. Is it a normal ? I thought it create only one instance...
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Ondina D.F. on 30 Aug, 2012 03:12 PM
Hi Pascal,
The answer to your question is in here:
https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...
"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.
"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.
hth
Ondina
2 Posted by Pascal on 30 Aug, 2012 03:18 PM
Ok, thanks Ondina !
Support Staff 3 Posted by Ondina D.F. on 30 Aug, 2012 03:20 PM
My pleasure!
Ondina D.F. closed this discussion on 30 Aug, 2012 03:20 PM.