Skip to content

[4.x only] feat(compiler): should only inject services annotated with @Injectable - #14931

Closed
DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/13820
Closed

DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/13820

Conversation

@DzmitryShylovich

Copy link
Copy Markdown
Contributor

Closes #12467
Closes #13820

BREAKING CHANGE: Before this commit it was not nessesary to add
@Injectable when a service had contructor without args or if any other
decorator was applied. After this commit @Injectable is mandatory for
all services provided using useClass.

Before:

class SomeService {}

@component({selector: 'my-app', template: ''})
class AppComponent {
  constructor(service: SomeService) {}
}

After:

@Injectable()
class SomeService {}

@component({selector: 'my-app', template: ''})
class AppComponent {
  constructor(service: SomeService) {}
}

Closes angular#12467
Closes angular#13820
@lacolaco

Copy link
Copy Markdown
Contributor

it can make a huge impact on existing apps. I think it needs deprecation phase and warning message.

@Toxicable

Toxicable commented Mar 13, 2017 •

Copy link
Copy Markdown

@laco0416 I agree it will have a huge impact but what exactly is it deprecating? and it does have a warning message: syntaxError('${stringifyType(identifier)} must be annotated with @Injectable'));

@lacolaco

lacolaco commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

I expect it emits only warning messages without any effects on application behaviors.

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

@laco0416

it can make a huge impact on existing apps

don't think so. it's already recommended in the style guide to always use Injectable.

@lacolaco

lacolaco commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

First, the style guide says only "Use @Injectable() instead of @Inject()".

https://angular.io/docs/ts/latest/guide/style-guide.html#!#07-04

Do use the @Injectable class decorator instead of the @Inject parameter decorator when using types as tokens for the dependencies of a service.

And as you say, the recommendation is existing at https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#injectable . but this is just a suggestion. not a warning.

Angular hasn't warned Injectable-less services anywhere yet. It's not ready to be broken.

@chuckjaz chuckjaz added area: core Issues related to the framework runtime feature Label used to distinguish feature request from other issues labels May 23, 2017
@vicb

vicb commented Feb 13, 2018

Copy link
Copy Markdown
Contributor

Only security fixes go to 4.x

@vicb vicb closed this Feb 13, 2018
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime cla: yes feature Label used to distinguish feature request from other issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[4.x] Don't allow injecting classes without @Injectable Improve error message for when Injectable() is missing

6 participants