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

Consider supporting forwardRef in providedIn fields of @Injectable decorators #41205

Closed
AndrewKushnir opened this issue Mar 14, 2021 · 1 comment
Assignees
Labels
area: core Issues related to the framework runtime feature Issue that requests a new feature state: has PR
Milestone

Comments

@AndrewKushnir
Copy link
Contributor

🚀 feature request

Relevant Package

@angular/core

Description

@Injectable decorators support passing an NgModule reference as a value of the providedIn field, for ex:

@Injectable({ providedIn: MyModule })
class MyProvider {}

This makes the provider tree-shakable (as this provider is not referenced directly inside an NgModule def).

Currently, there is no forwardRef support in the providedIn field of the @Injectable decorator, which forces the limitation of defining an NgModule before an Injectable class. In some cases this is very inconvenient, see PR #41126.

Describe the solution you'd like

We should consider adding forwardRef support to the providedIn property values, so the example above may look like this:

@Injectable({ providedIn: forwardRef(() => MyModule) })
class MyProvider {}
@AndrewKushnir AndrewKushnir added feature Issue that requests a new feature area: core Issues related to the framework runtime labels Mar 14, 2021
@ngbot ngbot bot modified the milestone: Backlog Mar 14, 2021
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 2, 2021
…aration

Adds support for using a `forwardRef` inside of the `providedIn` of an `Injectable` declaration.

Fixes angular#41205.
@crisbeto crisbeto self-assigned this Apr 2, 2021
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 2, 2021
…aration

Adds support for using a `forwardRef` inside of the `providedIn` of an `Injectable` declaration.

Fixes angular#41205.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 3, 2021
…aration

Adds support for using a `forwardRef` inside of the `providedIn` of an `Injectable` declaration.

Fixes angular#41205.
@atscott atscott closed this as completed in f7c294e Apr 6, 2021
@angular-automatic-lock-bot
Copy link

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 May 7, 2021
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 feature Issue that requests a new feature state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants