feat(core): introduce runInInjectionContext and deprecate prior version#49396
feat(core): introduce runInInjectionContext and deprecate prior version#49396alxhub wants to merge 1 commit intoangular:mainfrom
runInInjectionContext and deprecate prior version#49396Conversation
cbce19a to
021be49
Compare
|
Wouldn't that solve #47566 ? |
packages/core/src/di/contextual.ts
Outdated
There was a problem hiding this comment.
OOC, is this ReturnT a Google stylistic suggestion? Never really saw this outside Google in any major project anyway. Traditionally this would be only T if it's just 1 type generic, or more specifically here TReturn, but never the other way around o:
021be49 to
042b67a
Compare
atscott
left a comment
There was a problem hiding this comment.
reviewed-for: public-api, fw-core
jessicajaniuk
left a comment
There was a problem hiding this comment.
reviewed-for: fw-core, public-api
…sion With the introduction of `EnvironmentInjector`, we added an operation to run a function with access to `inject` tokens from that injector. This operation only worked for `EnvironmentInjector`s and not for element/node injectors. This commit deprecates `EnvironmentInjector.runInContext` in favor of a standalone API `runInInjectionContext`, which supports any type of injector. DEPRECATED: `EnvironmentInjector.runInContext` is now deprecated, with `runInInjectionContext` functioning as a direct replacement: ```typescript // Previous method version (deprecated): envInjector.runInContext(fn); // New standalone function: runInInjectionContext(envInjector, fn); ```
042b67a to
4548b4b
Compare
| } | ||
|
|
||
| private assertNotDestroyed(): void { | ||
| assertNotDestroyed(): void { |
There was a problem hiding this comment.
| assertNotDestroyed(): void { | |
| /** @internal */ | |
| assertNotDestroyed(): void { |
There was a problem hiding this comment.
R3Injector is already internal / not exported as public.
| // @deprecated (undocumented) | ||
| abstract get(token: any, notFoundValue?: any): any; | ||
| // @deprecated | ||
| abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT; |
There was a problem hiding this comment.
I think it'd be great to reuse the runInInjectionContext function within the EnvironmentInjector.runInContext implementation (to avoid code duplication):
angular/packages/core/src/di/r3_injector.ts
Lines 217 to 228 in 7dbe328
There was a problem hiding this comment.
This isn't possible because runInInjectionContext depends on R3Injector so that would be a circular reference.
|
This PR was merged into the repository by commit 0814f20. |
|
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. |
With the introduction of
EnvironmentInjector, we added an operation to run a function with access toinjecttokens from that injector. This operation only worked forEnvironmentInjectors and not for element/node injectors.This commit deprecates
EnvironmentInjector.runInContextin favor of a standalone APIrunInInjectionContext, which supports any type of injector.DEPRECATION:
EnvironmentInjector.runInContextis now deprecated, withrunInInjectionContextfunctioning as a direct replacement: