-
Notifications
You must be signed in to change notification settings - Fork 89
getInstance implies that I will receive an instance irrespective of mapping. getMappedInstance would be more appropriate API #25
Comments
I went ahead and made this change in my childinjectors branch on my fork. |
I see that you've since rolled back your change. What made you reconsider? |
shaun yelled at me. ;) - not really, he sent me links and didn't like the change. I still don't like it, but it is consistant with SmartyPants and others so it is cool. I know it was debated a lot. |
hehe ;) |
"shaun yelled at me" hahaha!! that prick! but seriously, if getInstance didn't throw an error the world would become a strange and unpredictable place. The word "or" is the clue here. "Retrieve an instance from the container if a rule exists OR instantiate a new instance if one does not". There would be no way to tell the two scenarios apart. This is especially dangerous with singletons - you wouldn't be able to tell if you are being given a singleton (as you might expect due to some design) or a new instance. "instantiate" already causes some confusion in this regard: people map a singleton and then use "instantiate" expecting to be given the same instance that other parts of the system will be given.. but that's not what happens of course. "getInstance" is the remedy to this scenario, and having it fall back to "instantiate" behavior just muddies the waters :) |
I fully concur! I also agree about instantiate being a bit unfortunate. I think 2.0 will see some interface cleanup during which instantiate might just as well get lost. |
Ah yes, but instantiate is still useful: MediatorMap, CommandMap - places where we actually want new instances (regardless of rules) with fully satisfied dependencies (including ctor args). |
You absolutely insist on having the last word on this entire topic, don't you? ;) (Obviously, being right helps with that ...) |
Yes. |
I still really think that getInstance should not throw an error, but instead provide an instance of the class via Injector#instantiate. The API suggests to me that I am going to get an instance, not an error. Otherwise it should be getMappedInstance to let me know that is a very specific call.
The text was updated successfully, but these errors were encountered: