-
Notifications
You must be signed in to change notification settings - Fork 26.2k
/
Copy pathinjectable.ts
111 lines (104 loc) · 3.2 KB
/
injectable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Type} from '../interface/type';
import {makeDecorator, TypeDecorator} from '../util/decorators';
import {
ClassSansProvider,
ConstructorSansProvider,
ExistingSansProvider,
FactorySansProvider,
StaticClassSansProvider,
ValueSansProvider,
} from './interface/provider';
import {compileInjectable} from './jit/injectable';
export {compileInjectable};
/**
* Injectable providers used in `@Injectable` decorator.
*
* @publicApi
*/
export type InjectableProvider =
| ValueSansProvider
| ExistingSansProvider
| StaticClassSansProvider
| ConstructorSansProvider
| FactorySansProvider
| ClassSansProvider;
/**
* Type of the Injectable decorator / constructor function.
*
* @publicApi
*/
export interface InjectableDecorator {
/**
* Decorator that marks a class as available to be
* provided and injected as a dependency.
*
* @see [Introduction to Services and DI](guide/di)
* @see [Dependency Injection Guide](guide/di/dependency-injection
*
* @usageNotes
*
* Marking a class with `@Injectable` ensures that the compiler
* will generate the necessary metadata to create the class's
* dependencies when the class is injected.
*
* The following example shows how a service class is properly
* marked so that a supporting service can be injected upon creation.
*
* {@example core/di/ts/metadata_spec.ts region='Injectable'}
*
*/
(): TypeDecorator;
(
options?: {providedIn: Type<any> | 'root' | 'platform' | 'any' | null} & InjectableProvider,
): TypeDecorator;
new (): Injectable;
new (
options?: {providedIn: Type<any> | 'root' | 'platform' | 'any' | null} & InjectableProvider,
): Injectable;
}
/**
* Type of the Injectable metadata.
*
* @publicApi
*/
export interface Injectable {
/**
* Determines which injectors will provide the injectable.
*
* - `Type<any>` - associates the injectable with an `@NgModule` or other `InjectorType`. This
* option is DEPRECATED.
* - 'null' : Equivalent to `undefined`. The injectable is not provided in any scope automatically
* and must be added to a `providers` array of an [@NgModule](api/core/NgModule#providers),
* [@Component](api/core/Directive#providers) or [@Directive](api/core/Directive#providers).
*
* The following options specify that this injectable should be provided in one of the following
* injectors:
* - 'root' : The application-level injector in most apps.
* - 'platform' : A special singleton platform injector shared by all
* applications on the page.
* - 'any' : Provides a unique instance in each lazy loaded module while all eagerly loaded
* modules share one instance. This option is DEPRECATED.
*
*/
providedIn?: Type<any> | 'root' | 'platform' | 'any' | null;
}
/**
* Injectable decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Injectable: InjectableDecorator = makeDecorator(
'Injectable',
undefined,
undefined,
undefined,
(type: Type<any>, meta: Injectable) => compileInjectable(type as any, meta),
);