Non-singletons that are registered in a container are actually singletons when they get dependency injected


I want to inject an instance of a certain controller into every instance of a certain view type. The view is rendered/instantiated with:

{{view "view-name"}}

from within a template. I passed in {singleton: false} as options object for App.register but the controller is still only instantiated once. How to ensure that every view object gets its very own controller instance? See this jsbin:

I realized that it has nothing to do with {{view}}. The same thing happens when looking up a view class directly. e.g.


will create 3 new view instances but the injected alternatives instance is always the same.

So I have digged into the code of lookup() and found out that lookup() searches for the class to instantiate and then caches it. Injections will only get looked up when the class is not cached yet, which leaves the injected dependency as a singleton no matter if singleton is set to false in register().

I’m not sure if this is a bug or works as intended.


this is a known bug, and an issue exists tracking it.