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

[BUGFIX] Ensure that dynamic injections are not cacheable in a Container. #10173

Merged
merged 2 commits into from
Aug 12, 2015

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented Jan 8, 2015

A non-singleton injection should prevent caching of an object or factory instance in a container.

Fixes #3310

@rwjblue
Copy link
Member

rwjblue commented Jan 8, 2015

LGTM, @stefanpenner - r?

@@ -182,6 +182,10 @@ Container.prototype = {
}
})();

function isSingleton(container, fullName) {
return container._registry.getOption(fullName, 'singleton') !== false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !container._registry.getOption(fullName, 'singleton') perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even return container._registry.getOption(fullName, 'singleton') if I'm reading this code correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The singleton option by default is true, so neither alternative above would work for all cases (true, false, undefined). One alternative that would work is return !!container._registry.getOption(fullName, 'singleton'); - I'm guessing that's what you meant with your first suggestion. Anyway, I'd be glad to change to this if it's more a more common convention throughout ember. There are other instances of checking !== false throughout the Container which I could also change to !! if there's consensus on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I don't see an upside to being more accepting of truthy / falsy values in settings completely controlled by developers (which should therefore have explicit values like false), so I'd recommend keeping it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's keep it matching the exact value specified.

@rwjblue
Copy link
Member

rwjblue commented Aug 2, 2015

@dgeb - This looks good, but needs a rebase. Can you confirm this is still needed (after the container/registry reform PR's) and rebase ?

@rwjblue
Copy link
Member

rwjblue commented Aug 9, 2015

@dgeb - Ping?

A non-singleton injection should prevent caching of an object or factory
instance in a container.

[Fixes emberjs#3310]
@dgeb
Copy link
Member Author

dgeb commented Aug 12, 2015

@rwjblue I can confirm this is still needed via the test that's included, which fails if injections aren't marked as dynamic.

I've just rebased against master.

rwjblue added a commit that referenced this pull request Aug 12, 2015
[BUGFIX] Ensure that dynamic injections are not cacheable in a Container.
@rwjblue rwjblue merged commit 4a8d9a3 into emberjs:master Aug 12, 2015
@rwjblue
Copy link
Member

rwjblue commented Aug 12, 2015

Thank you @dgeb!

@dgeb dgeb deleted the fix-3310 branch August 12, 2015 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non singleton injections are treated as singleton
4 participants