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
Introducing EnvInjector! #45626
Introducing EnvInjector! #45626
Conversation
424d469
to
ba03f2f
Compare
ca6934c
to
ab2815d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 👍 Just left a few minor comments (none of them are blockers, we can update things in followup PRs).
packages/core/src/di/r3_injector.ts
Outdated
* created by the framework. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* created by the framework. | |
*/ | |
* created by the framework. | |
* | |
* @publicApi | |
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: size-tracking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api, size-tracking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🍪
Just a few non-blocking comments.
packages/core/src/di/r3_injector.ts
Outdated
|
||
// Make sure the INJECTOR token provides this injector. | ||
this.records.set(INJECTOR, makeRecord(undefined, this)); | ||
|
||
// And `EnvironmentInjector` if the current injector is supposed to be env-scoped. | ||
if (scopes.has('env')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's another instance of env
. Is there any way to make these not magic strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're sort of by definition magic strings, since they're typically generated by the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api, size-tracking
Previously there was a test ordering issue with the application_module_spec tests where the value of `getLocaleId()` depended on the order in which tests ran. Specifically, `setLocaleId()` lower-cases the current locale ID, so the measured value in a test depended on whether a previous test had called `setLocaleId()` (the difference between 'en-US' and 'en-us').
9d8065d
to
dcae004
Compare
e173bf1
to
c72330f
Compare
This commit implements the `importProvidersFrom` function that allows extracting a list of `Provider`s from a list of NgModule types. The R3Injector which implements DI at the "module" level for Angular is refactored to use this functionality under the hood. This commit also implements `INJECTOR_INITIALIZER`, a DI multi-provider token which is used to run initialization logic when an injector is created.
@@ -138,7 +138,7 @@ export {CssSelectorList, ProjectionSlots} from './interfaces/projection'; | |||
export { | |||
setClassMetadata, | |||
} from './metadata'; | |||
export {NgModuleFactory, NgModuleRef} from './ng_module_ref'; | |||
export {NgModuleFactory, NgModuleRef, createEnvironmentInjector} from './ng_module_ref'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: import without usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an export
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG, tired brain :-)
This commit exposes a new `EnvironmentInjector` abstraction, which generalizes the "module injector" concept to injectors that are not based on NgModules. An EnvironmentInjector is a conceptual analogue of an `NgModuleRef` - it represents an injector on the former "module" DI hierarchy in Angular (now renamed to the "environment injector hierarchy"). Environment injectors are created via the `createEnvironmentInjector` function from a list of `Provider`s. For backwards compatibility with current code using `NgModuleRef`, `EnvironmentInjector`s are wrapped by an adapter `NgModuleRef` implementation, so injecting `NgModuleRef` always returns the latest `EnvironmentInjector`, even if that injector was not based on an NgModule. Conversely, NgModule-based `NgModuleRef`s created via `createNgModuleRef` are _also_ `EnvironmentInjector`s.
This commit adds a new internal scope to `R3Injector` for `EnvironmentInjector`s specifically. This will allow us to scope services to the environment side of the injector hierarchy specifically, as opposed to the `'any'` scope which also includes view-side injectors created via `Injector.create`. For now, this functionality is not exposed publicly, but is available to use within `@angular/core` only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
Caretaker: this has all required approvals |
This PR was merged into the repository by commit 3578e94. |
This commit implements the `importProvidersFrom` function that allows extracting a list of `Provider`s from a list of NgModule types. The R3Injector which implements DI at the "module" level for Angular is refactored to use this functionality under the hood. This commit also implements `INJECTOR_INITIALIZER`, a DI multi-provider token which is used to run initialization logic when an injector is created. PR Close #45626
…#45626) This commit exposes a new `EnvironmentInjector` abstraction, which generalizes the "module injector" concept to injectors that are not based on NgModules. An EnvironmentInjector is a conceptual analogue of an `NgModuleRef` - it represents an injector on the former "module" DI hierarchy in Angular (now renamed to the "environment injector hierarchy"). Environment injectors are created via the `createEnvironmentInjector` function from a list of `Provider`s. For backwards compatibility with current code using `NgModuleRef`, `EnvironmentInjector`s are wrapped by an adapter `NgModuleRef` implementation, so injecting `NgModuleRef` always returns the latest `EnvironmentInjector`, even if that injector was not based on an NgModule. Conversely, NgModule-based `NgModuleRef`s created via `createNgModuleRef` are _also_ `EnvironmentInjector`s. PR Close #45626
This commit adds a new internal scope to `R3Injector` for `EnvironmentInjector`s specifically. This will allow us to scope services to the environment side of the injector hierarchy specifically, as opposed to the `'any'` scope which also includes view-side injectors created via `Injector.create`. For now, this functionality is not exposed publicly, but is available to use within `@angular/core` only. PR Close #45626
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR includes a couple commits which introduce the new
EnvInjector
concept.EnvInjector
is a generalized version ofNgModuleRef
which represents the "module injector" (now renamed to "environment injector"). It's one of the primitives needed to support upcoming standalone components APIs.