Skip to content

Commit

Permalink
Deprecate owner.inject
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Jul 25, 2021
1 parent fc09fef commit a11ae84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 15 additions & 1 deletion packages/@ember/-internals/container/lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Factory } from '@ember/-internals/owner';
import { dictionary, intern } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { assert, deprecate } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import Container, { ContainerOptions, LazyInjection } from './container';

Expand Down Expand Up @@ -566,6 +566,20 @@ export default class Registry implements IRegistry {
this.isValidFullName(injectionName)
);

deprecate(
`owner.inject has been deprecated and will be removed in v5.0.0. Please refactor to explicitly instantiate ${property} on ${fullName}`,
false,
{
id: 'remove-owner-inject',
until: '5.0.0',
url: 'TODO',
for: 'ember-source',
since: {
enabled: '4.0.0',
},
}
);

let normalizedInjectionName = this.normalize(injectionName);

if (fullName.indexOf(':') === -1) {
Expand Down
11 changes: 6 additions & 5 deletions packages/@ember/application/lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,6 @@ const Application = Engine.extend({
} else { // node
application.register('service:network', NodeNetworkService);
}
application.inject('route', 'network', 'service:network');
};
export default {
Expand All @@ -1050,13 +1048,16 @@ const Application = Engine.extend({
```app/routes/post.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
// An example of how the (hypothetical) service is used in routes.
export default Route.extend({
export default class IndexRoute extends Route {
@service network;
model(params) {
return this.network.fetch(`/api/posts/${params.post_id}.json`);
},
}
afterModel(post) {
if (post.isExternalContent) {
Expand All @@ -1065,7 +1066,7 @@ const Application = Engine.extend({
return post;
}
}
});
}
```
```javascript
Expand Down

0 comments on commit a11ae84

Please sign in to comment.