ember-learn / guides-source

This repository contains the Ember.js Guides
https://guides.emberjs.com/
MIT License
159 stars 494 forks source link

import { inject } vs import { service } #2004

Closed rgaiacs closed 7 months ago

rgaiacs commented 7 months ago

https://guides.emberjs.com/release/applications/dependency-injection/#toc_ad-hoc-injections says

Dependency injections can also be declared directly on Ember classes using inject. Currently, inject supports injecting controllers (via import { inject } from '@ember/controller';) and services (via import { inject } from '@ember/service';).

but the example uses import { service } from '@ember/service';

Can I have a clarification of import { inject } vs import { service }?

NullVoxPopuli commented 7 months ago

They do the name thing 🙃 Inject is 'the old thing'

The docs need updated (simply for consistency and less typing), service should be preferred, tho my RFC to deprecate inject is low priority atm.

https://github.com/emberjs/rfcs/pull/1001

IgnaceMaes commented 7 months ago

Importing as service is indeed preferred.

It was adjusted in the code examples (see https://github.com/ember-learn/guides-source/pull/1766). But it looks like this usage was over. A PR to change it would be appreciated!

rgaiacs commented 7 months ago

Thanks for the clarification! https://github.com/ember-learn/guides-source/pull/1766 looks good to me. I will close this.