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 beta] Ensure container can still be provided to .create. #12731

Merged
merged 1 commit into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import dictionary from 'ember-metal/dictionary';
import isEnabled from 'ember-metal/features';
import { setOwner, OWNER } from './owner';
import { buildFakeContainerWithDeprecations } from 'ember-runtime/mixins/container_proxy';
import symbol from 'ember-metal/symbol';

const CONTAINER_OVERRIDE = symbol('CONTAINER_OVERRIDE');

/**
A container used to instantiate and cache objects.
Expand All @@ -27,6 +30,7 @@ function Container(registry, options) {

if (isEnabled('ember-container-inject-owner')) {
this._fakeContainerToInject = buildFakeContainerWithDeprecations(this);
this[CONTAINER_OVERRIDE] = undefined;
}
}

Expand Down Expand Up @@ -404,7 +408,19 @@ function injectDeprecatedContainer(object, container) {
deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.',
false,
{ id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });
return container;
return this[CONTAINER_OVERRIDE] || container;
},

set(value) {
deprecate(
`Providing the \`container\` property to ${this} is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection()\` instead to provide an owner to the instance being created.`,
false,
{ id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' }
);

this[CONTAINER_OVERRIDE] = value;

return value;
}
});
}
Expand Down
22 changes: 22 additions & 0 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,28 @@ if (isEnabled('ember-container-inject-owner')) {

equal(otherController.container, 'foo', 'container was not added');
});

QUnit.test('An extendable factory can provide `container` upon create, with a deprecation', function(assert) {
let registry = new Registry();
let container = registry.container();

registry.register('controller:post', factory());

let PostController = container.lookupFactory('controller:post');

let postController;

expectDeprecation(function() {
postController = PostController.create({
container: 'foo'
});
}, /Providing the \`container\` property to .+ is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection\(\)\` instead to provide an owner to the instance being created/);

expectDeprecation(function() {
let c = postController.container;
assert.equal(c, 'foo', 'the `container` provided to `.create`was used');
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');
});
} else {
QUnit.test('A `container` property is appended to every instantiated object', function() {
let registry = new Registry();
Expand Down