From a11ae84033ddaa8dbdd6bf028871beec6e9cb9b0 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 25 Jul 2021 12:23:40 -0500 Subject: [PATCH] Deprecate owner.inject --- .../@ember/-internals/container/lib/registry.ts | 16 +++++++++++++++- packages/@ember/application/lib/application.js | 11 ++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/@ember/-internals/container/lib/registry.ts b/packages/@ember/-internals/container/lib/registry.ts index 6d8634d8537..493010e4bc5 100644 --- a/packages/@ember/-internals/container/lib/registry.ts +++ b/packages/@ember/-internals/container/lib/registry.ts @@ -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'; @@ -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) { diff --git a/packages/@ember/application/lib/application.js b/packages/@ember/application/lib/application.js index 1a65185c961..ed7cd908f1b 100644 --- a/packages/@ember/application/lib/application.js +++ b/packages/@ember/application/lib/application.js @@ -1038,8 +1038,6 @@ const Application = Engine.extend({ } else { // node application.register('service:network', NodeNetworkService); } - - application.inject('route', 'network', 'service:network'); }; export default { @@ -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) { @@ -1065,7 +1066,7 @@ const Application = Engine.extend({ return post; } } - }); + } ``` ```javascript