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

Remove automatic injections #41

Closed
buschtoens opened this issue Jul 31, 2020 · 6 comments
Closed

Remove automatic injections #41

buschtoens opened this issue Jul 31, 2020 · 6 comments

Comments

@buschtoens
Copy link
Contributor

buschtoens commented Jul 31, 2020

export function initialize() {
const application = arguments[1] || arguments[0];
application.inject('controller', 'userAgent', 'service:userAgent');
application.inject('component', 'userAgent', 'service:userAgent');
application.inject('route', 'userAgent', 'service:userAgent');
application.inject('view', 'userAgent', 'service:userAgent');
}

Initializers and implicit automatic injections are becoming somewhat of an anit-pattern lately. I would recommend to remove them.

I just got bitten by this, because I was tying to inject a service with a different name (native/user-agent) as userAgent, but got ember-useragents service, as it's auto-injected before.

@snewcomer
Copy link

hi! Ping on this.

specifically, ember v4.0 will not work with this pattern.

emberjs/ember.js#19680

@buschtoens
Copy link
Contributor Author

It is unquestionable, that these implicit injections will have to be removed eventually due to emberjs/ember.js#19680. Thus I recommend that anyone wanting to or currently using this addon, overrides https://github.com/willviles/ember-useragent/blob/master/app/initializers/user-agent.js in their own app with a no-op, like:

// app/initializers/user-agent.js
export function initialize() {}

This way the implicit injections are already disabled and you can't accidentally make use of them. Please note, that if you're making this change in an app that already uses ember-useragent, you should regression test it to ensure, you haven't already used these implicit injections accidentally.

@buschtoens
Copy link
Contributor Author

buschtoens commented Aug 19, 2021

As a way forward for ember-useragent itself, I would recommend to replace the application.inject(...) usages with custom macros, that raise a deprecation, when accessed. This allows users to discover and migrate all the callsites accidentally relying on these implicit injections bit by bit.

Optionally configuration could be included, to completely disable the injection, which should be recommended to be enabled by all new users. This way the breaking release can be delayed indefinitely, all the while being ready for Ember 4.0.

@snewcomer
Copy link

with custom macros, that raise a deprecation, when accessed. This allows users to discover and migrate all the callsites accidentally relying on these implicit injections bit by bit

I think we already did this for users in ember-source >= 3.26

emberjs/ember.js#19358

@buschtoens
Copy link
Contributor Author

@snewcomer perfect, thanks! I wasn't sure any more and didn't re-read.

@willviles
Copy link
Owner

Released in 0.11.0. Thanks for all contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants