Skip to content

Commit 24c5398

Browse files
refactor(core): Support and document manually provided internal injections (#60347)
For internal framework values stored in injectors, they are manually managed and inserted into injectors as needed. Therefore their tokens don't provide a value or factory. This updates the type to reflect that and updates the jsdocs a bit. PR Close #60347
1 parent f030409 commit 24c5398

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

packages/core/primitives/di/src/injection_token.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,32 @@
88

99
import {Type} from './type';
1010
/**
11-
* Information about how a type or `InjectionToken` interfaces with the DI system.
11+
* Information about how a type or `InjectionToken` interfaces with the DI
12+
* system. This describes:
1213
*
13-
* At a minimum, this includes a `factory` which defines how to create the given type `T`, possibly
14-
* requesting injection of other types if necessary.
14+
* 1. *How* the type is provided
15+
* The declaration must specify only one of the following:
16+
* - A `value` which is a predefined instance of the type.
17+
* - A `factory` which defines how to create the given type `T`, possibly
18+
* requesting injection of other types if necessary.
19+
* - Neither, in which case the type is expected to already be present in the
20+
* injector hierarchy. This is used for internal use cases.
1521
*
16-
* Optionally, a `providedIn` parameter specifies that the given type belongs to a particular
17-
* `Injector`, `NgModule`, or a special scope (e.g. `'root'`). A value of `null` indicates
18-
* that the injectable does not belong to any scope.
22+
* 2. *Where* the type is stored (if it is stored)
23+
* - The `providedIn` parameter specifies which injector the type belongs to.
24+
* - The `token` is used as the key to store the type in the injector.
1925
*/
2026
export interface ɵɵInjectableDeclaration<T> {
2127
/**
22-
* Specifies that the given type belongs to a particular injector:
28+
* Specifies that the given type belongs to a particular `Injector`,
29+
* `NgModule`, or a special scope (e.g. `'root'`).
30+
*
31+
* `any` is deprecated and will be removed soon.
32+
*
33+
* A value of `null` indicates that the injectable does not belong to any
34+
* scope, and won't be stored in any injector. For declarations with a
35+
* factory, this will create a new instance of the type each time it is
36+
* requested.
2337
*/
2438
providedIn: Type<any> | 'root' | 'platform' | 'any' | null;
2539

@@ -33,12 +47,12 @@ export interface ɵɵInjectableDeclaration<T> {
3347
/**
3448
* Factory method to execute to create an instance of the injectable.
3549
*/
36-
factory: (t?: Type<any>) => T;
50+
factory?: (t?: Type<any>) => T;
3751

3852
/**
3953
* In a case of no explicit injector, a location where the instance of the injectable is stored.
4054
*/
41-
value: T | undefined;
55+
value?: T;
4256
}
4357

4458
/**

0 commit comments

Comments
 (0)