Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non singleton injections are treated as singleton #3310

Closed
taras opened this issue Sep 3, 2013 · 14 comments · Fixed by #10173
Closed

Non singleton injections are treated as singleton #3310

taras opened this issue Sep 3, 2013 · 14 comments · Fixed by #10173
Assignees
Labels

Comments

@taras
Copy link
Contributor

taras commented Sep 3, 2013

I'm trying to figure out if I found a bug or I'm just misunderstanding register/inject functionality.

JSBin shows multiple instances of person are created using lookup and I would expect for each person to have a unique instance of App.FavoriteFruit because its injected into person as a non-singleton injection.

The failing test shows that different instances of people are created but they share an instance of favorite fruit.

Is this a bug? ( tests don't cover this scenario )

@taras
Copy link
Contributor Author

taras commented Sep 3, 2013

Ok

@stefanpenner
Copy link
Member

@taras I'm available on irc #emberjs if you want further clarification. This part of ember does lack guides.

@taras
Copy link
Contributor Author

taras commented Sep 5, 2013

@stefanpenner I tried to find you on IRC but I don't know your handle.

I'm not sure if you looked at my JSBin, but it seems like a very awkward inconsistency to support singleton:false with container.lookup() but not when it's injected.

Here is original http://jsbin.com/aguLeDi/11/edit and another http://jsbin.com/usaluc/12/edit by @intuitivepixel that shows singleton injections working when injected into controllers.

Could you please take another look at this?

@ghost ghost assigned stefanpenner Sep 5, 2013
@stefanpenner
Copy link
Member

reopening, till i have a chance to digest the above request.

@stefanpenner stefanpenner reopened this Sep 5, 2013
lukemelia added a commit to lukemelia/ember.js that referenced this issue Sep 8, 2013
@lukemelia
Copy link
Member

@stefanpenner @taras I've narrowed down a failing test for this: https://github.com/lukemelia/ember.js/compare/injections-fix?expand=1

The issue is in the factory caching in factoryFor (https://github.com/emberjs/ember.js/blob/master/packages/container/lib/main.js#L802). It doesn't take into account the fact that the injections may be singleton: false. Commenting out that lines makes the test pass, but obviously a more nuanced fix would be preferable. Thoughts?

@stefanpenner
Copy link
Member

@lukemelia thanks for digging into this

Ya, commenting that out would mean every instance gets it own factory, which is non-deal.

I have a proper solution in mind. Specifically, the work @kselden and I have been discussing would solve this.

@taras
Copy link
Contributor Author

taras commented Sep 8, 2013

@lukemelia thank you for looking into this.

@wagenet
Copy link
Member

wagenet commented Oct 13, 2013

@stefanpenner is this fixed?

@wagenet
Copy link
Member

wagenet commented Nov 9, 2013

@stefanpenner ping.

@stefanpenner
Copy link
Member

not fixed, will be part of the next container related refactor.

@wagenet
Copy link
Member

wagenet commented Apr 12, 2014

@stefanpenner fixed yet?

@stefanpenner
Copy link
Member

no

@wagenet
Copy link
Member

wagenet commented Jul 28, 2014

#5266

@wagenet wagenet closed this as completed Jul 28, 2014
dgeb added a commit to dgeb/ember.js that referenced this issue Aug 12, 2015
A non-singleton injection should prevent caching of an object or factory
instance in a container.

[Fixes emberjs#3310]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants