static-injector 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/import/commonjs/index.js +1248 -0
- package/import/es2015/decorator/injectable.js +14 -0
- package/import/es2015/decorator/interface/provider.js +8 -0
- package/import/es2015/di/forward_ref.js +53 -0
- package/import/es2015/di/inject_switch.js +31 -0
- package/import/es2015/di/injection_token.js +71 -0
- package/import/es2015/di/injector.js +63 -0
- package/import/es2015/di/injector_compatibility.js +172 -0
- package/import/es2015/di/injector_marker.js +8 -0
- package/import/es2015/di/injector_token.js +21 -0
- package/import/es2015/di/interface/defs.js +72 -0
- package/import/es2015/di/interface/injector.js +25 -0
- package/import/es2015/di/interface/provider.js +8 -0
- package/import/es2015/di/metadata.js +49 -0
- package/import/es2015/di/null_injector.js +19 -0
- package/import/es2015/di/provider_token.js +8 -0
- package/import/es2015/di/r3_injector.js +382 -0
- package/import/es2015/di/scope.js +14 -0
- package/import/es2015/index.js +11 -0
- package/import/es2015/interface/lifecycle_hooks.js +8 -0
- package/import/es2015/interface/type.js +8 -0
- package/import/es2015/render3/definition_factory.js +15 -0
- package/import/es2015/render3/error_code.js +29 -0
- package/import/es2015/render3/errors_di.js +14 -0
- package/import/es2015/render3/fields.js +11 -0
- package/import/es2015/render3/instructions/di.js +23 -0
- package/import/es2015/render3/util/stringify_utils.js +37 -0
- package/import/es2015/util/array_utils.js +17 -0
- package/import/es2015/util/closure.js +19 -0
- package/import/es2015/util/decorators.js +30 -0
- package/import/es2015/util/empty.js +14 -0
- package/import/es2015/util/property.js +15 -0
- package/import/es2015/util/stringify.js +30 -0
- package/import/fesm2015/index.js +1211 -0
- package/import/typings/decorator/injectable.d.ts +82 -0
- package/import/typings/decorator/interface/provider.d.ts +312 -0
- package/import/typings/di/forward_ref.d.ts +49 -0
- package/import/typings/di/inject_switch.d.ts +17 -0
- package/import/typings/di/injection_token.d.ts +57 -0
- package/import/typings/di/injector.d.ts +76 -0
- package/import/typings/di/injector_compatibility.d.ts +77 -0
- package/import/typings/di/injector_marker.d.ts +23 -0
- package/import/typings/di/injector_token.d.ts +18 -0
- package/import/typings/di/interface/defs.d.ts +155 -0
- package/import/typings/di/interface/injector.d.ts +48 -0
- package/import/typings/di/interface/provider.d.ts +312 -0
- package/import/typings/di/metadata.d.ts +176 -0
- package/import/typings/di/null_injector.d.ts +11 -0
- package/import/typings/di/provider_token.d.ts +17 -0
- package/import/typings/di/r3_injector.d.ts +92 -0
- package/import/typings/di/scope.d.ts +14 -0
- package/import/typings/index.d.ts +11 -0
- package/import/typings/interface/lifecycle_hooks.d.ts +28 -0
- package/import/typings/interface/type.d.ts +21 -0
- package/import/typings/render3/definition_factory.d.ts +24 -0
- package/import/typings/render3/error_code.d.ts +24 -0
- package/import/typings/render3/errors_di.d.ts +2 -0
- package/import/typings/render3/fields.d.ts +8 -0
- package/import/typings/render3/instructions/di.d.ts +20 -0
- package/import/typings/render3/util/stringify_utils.d.ts +20 -0
- package/import/typings/util/array_utils.d.ts +10 -0
- package/import/typings/util/closure.d.ts +17 -0
- package/import/typings/util/decorators.d.ts +27 -0
- package/import/typings/util/empty.d.ts +14 -0
- package/import/typings/util/property.d.ts +8 -0
- package/import/typings/util/stringify.d.ts +8 -0
- package/package.json +34 -0
- package/readme.md +27 -0
- package/transform/compiler/index.d.ts +5 -0
- package/transform/compiler/index.js +17 -0
- package/transform/compiler/src/core.d.ts +19 -0
- package/transform/compiler/src/core.js +9 -0
- package/transform/compiler/src/injectable_compiler_2.d.ts +53 -0
- package/transform/compiler/src/injectable_compiler_2.js +159 -0
- package/transform/compiler/src/output/output_ast.d.ts +534 -0
- package/transform/compiler/src/output/output_ast.js +986 -0
- package/transform/compiler/src/parse_util.d.ts +50 -0
- package/transform/compiler/src/parse_util.js +61 -0
- package/transform/compiler/src/render3/partial/api.d.ts +166 -0
- package/transform/compiler/src/render3/partial/api.js +11 -0
- package/transform/compiler/src/render3/partial/util.d.ts +16 -0
- package/transform/compiler/src/render3/partial/util.js +44 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +97 -0
- package/transform/compiler/src/render3/r3_factory.js +239 -0
- package/transform/compiler/src/render3/r3_identifiers.d.ts +20 -0
- package/transform/compiler/src/render3/r3_identifiers.js +51 -0
- package/transform/compiler/src/render3/util.d.ts +21 -0
- package/transform/compiler/src/render3/util.js +41 -0
- package/transform/compiler/src/render3/view/util.d.ts +30 -0
- package/transform/compiler/src/render3/view/util.js +57 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +21 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +42 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +278 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.d.ts +91 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +370 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +76 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +188 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +206 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +13 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +36 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.js +25 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +3 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +15 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +667 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +98 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +271 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +50 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +396 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +12 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +45 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +115 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +30 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +15 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +84 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +5 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.js +17 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +274 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +18 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +29 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +70 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +58 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +270 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +54 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +245 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +13 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +21 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +39 -0
- package/transform/index.d.ts +1 -0
- package/transform/index.js +13 -0
- package/transform/injectable-transform.d.ts +41 -0
- package/transform/injectable-transform.js +195 -0
- package/transform/node-Iteration.d.ts +2 -0
- package/transform/node-Iteration.js +12 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from '../interface/type';
|
|
9
|
+
import { TypeDecorator } from '../util/decorators';
|
|
10
|
+
import { ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider } from './interface/provider';
|
|
11
|
+
/**
|
|
12
|
+
* Injectable providers used in `@Injectable` decorator.
|
|
13
|
+
*
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
export declare type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Type of the Injectable decorator / constructor function.
|
|
19
|
+
*
|
|
20
|
+
* @publicApi
|
|
21
|
+
*/
|
|
22
|
+
export interface InjectableDecorator {
|
|
23
|
+
/**
|
|
24
|
+
* Decorator that marks a class as available to be
|
|
25
|
+
* provided and injected as a dependency.
|
|
26
|
+
*
|
|
27
|
+
* @see [Introduction to Services and DI](guide/architecture-services)
|
|
28
|
+
* @see [Dependency Injection Guide](guide/dependency-injection)
|
|
29
|
+
*
|
|
30
|
+
* @usageNotes
|
|
31
|
+
*
|
|
32
|
+
* Marking a class with `@Injectable` ensures that the compiler
|
|
33
|
+
* will generate the necessary metadata to create the class's
|
|
34
|
+
* dependencies when the class is injected.
|
|
35
|
+
*
|
|
36
|
+
* The following example shows how a service class is properly
|
|
37
|
+
* marked so that a supporting service can be injected upon creation.
|
|
38
|
+
*
|
|
39
|
+
* <code-example path="core/di/ts/metadata_spec.ts" region="Injectable"></code-example>
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
(): TypeDecorator;
|
|
43
|
+
(options?: {
|
|
44
|
+
providedIn: Type<any> | 'root' | 'platform' | 'any' | null;
|
|
45
|
+
} & InjectableProvider): TypeDecorator;
|
|
46
|
+
new (): Injectable;
|
|
47
|
+
new (options?: {
|
|
48
|
+
providedIn: Type<any> | 'root' | 'platform' | 'any' | null;
|
|
49
|
+
} & InjectableProvider): Injectable;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type of the Injectable metadata.
|
|
53
|
+
*
|
|
54
|
+
* @publicApi
|
|
55
|
+
*/
|
|
56
|
+
export interface Injectable {
|
|
57
|
+
/**
|
|
58
|
+
* Determines which injectors will provide the injectable.
|
|
59
|
+
*
|
|
60
|
+
* - `Type<any>` - associates the injectable with an `@NgModule` or other `InjectorType`,
|
|
61
|
+
* - 'null' : Equivalent to `undefined`. The injectable is not provided in any scope automatically
|
|
62
|
+
* and must be added to a `providers` array of an [@NgModule](api/core/NgModule#providers),
|
|
63
|
+
* [@Component](api/core/Directive#providers) or [@Directive](api/core/Directive#providers).
|
|
64
|
+
*
|
|
65
|
+
* The following options specify that this injectable should be provided in one of the following
|
|
66
|
+
* injectors:
|
|
67
|
+
* - 'root' : The application-level injector in most apps.
|
|
68
|
+
* - 'platform' : A special singleton platform injector shared by all
|
|
69
|
+
* applications on the page.
|
|
70
|
+
* - 'any' : Provides a unique instance in each lazy loaded module while all eagerly loaded
|
|
71
|
+
* modules share one instance.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
providedIn?: Type<any> | 'root' | 'platform' | 'any' | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Injectable decorator and metadata.
|
|
78
|
+
*
|
|
79
|
+
* @Annotation
|
|
80
|
+
* @publicApi
|
|
81
|
+
*/
|
|
82
|
+
export declare const Injectable: InjectableDecorator;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from '../../interface/type';
|
|
9
|
+
/**
|
|
10
|
+
* Configures the `Injector` to return a value for a token.
|
|
11
|
+
* Base for `ValueProvider` decorator.
|
|
12
|
+
*
|
|
13
|
+
* @publicApi
|
|
14
|
+
*/
|
|
15
|
+
export interface ValueSansProvider {
|
|
16
|
+
/**
|
|
17
|
+
* The value to inject.
|
|
18
|
+
*/
|
|
19
|
+
useValue: any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configures the `Injector` to return a value for a token.
|
|
23
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
24
|
+
*
|
|
25
|
+
* @usageNotes
|
|
26
|
+
*
|
|
27
|
+
* ### Example
|
|
28
|
+
*
|
|
29
|
+
* {@example core/di/ts/provider_spec.ts region='ValueProvider'}
|
|
30
|
+
*
|
|
31
|
+
* ### Multi-value example
|
|
32
|
+
*
|
|
33
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
34
|
+
*
|
|
35
|
+
* @publicApi
|
|
36
|
+
*/
|
|
37
|
+
export interface ValueProvider extends ValueSansProvider {
|
|
38
|
+
/**
|
|
39
|
+
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
|
40
|
+
*/
|
|
41
|
+
provide: any;
|
|
42
|
+
/**
|
|
43
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
44
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
45
|
+
*/
|
|
46
|
+
multi?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Configures the `Injector` to return an instance of `useClass` for a token.
|
|
50
|
+
* Base for `StaticClassProvider` decorator.
|
|
51
|
+
*
|
|
52
|
+
* @publicApi
|
|
53
|
+
*/
|
|
54
|
+
export interface StaticClassSansProvider {
|
|
55
|
+
/**
|
|
56
|
+
* An optional class to instantiate for the `token`. By default, the `provide`
|
|
57
|
+
* class is instantiated.
|
|
58
|
+
*/
|
|
59
|
+
useClass: Type<any>;
|
|
60
|
+
/**
|
|
61
|
+
* A list of `token`s to be resolved by the injector. The list of values is then
|
|
62
|
+
* used as arguments to the `useClass` constructor.
|
|
63
|
+
*/
|
|
64
|
+
deps: any[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Configures the `Injector` to return an instance of `useClass` for a token.
|
|
68
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
69
|
+
*
|
|
70
|
+
* @usageNotes
|
|
71
|
+
*
|
|
72
|
+
* {@example core/di/ts/provider_spec.ts region='StaticClassProvider'}
|
|
73
|
+
*
|
|
74
|
+
* Note that following two providers are not equal:
|
|
75
|
+
*
|
|
76
|
+
* {@example core/di/ts/provider_spec.ts region='StaticClassProviderDifference'}
|
|
77
|
+
*
|
|
78
|
+
* ### Multi-value example
|
|
79
|
+
*
|
|
80
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
81
|
+
*
|
|
82
|
+
* @publicApi
|
|
83
|
+
*/
|
|
84
|
+
export interface StaticClassProvider extends StaticClassSansProvider {
|
|
85
|
+
/**
|
|
86
|
+
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
|
87
|
+
*/
|
|
88
|
+
provide: any;
|
|
89
|
+
/**
|
|
90
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
91
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
92
|
+
*/
|
|
93
|
+
multi?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configures the `Injector` to return an instance of a token.
|
|
97
|
+
*
|
|
98
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
99
|
+
*
|
|
100
|
+
* @usageNotes
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* @Injectable(SomeModule, {deps: []})
|
|
104
|
+
* class MyService {}
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @publicApi
|
|
108
|
+
*/
|
|
109
|
+
export interface ConstructorSansProvider {
|
|
110
|
+
/**
|
|
111
|
+
* A list of `token`s to be resolved by the injector.
|
|
112
|
+
*/
|
|
113
|
+
deps?: any[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Configures the `Injector` to return an instance of a token.
|
|
117
|
+
*
|
|
118
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
119
|
+
*
|
|
120
|
+
* @usageNotes
|
|
121
|
+
*
|
|
122
|
+
* {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
|
|
123
|
+
*
|
|
124
|
+
* ### Multi-value example
|
|
125
|
+
*
|
|
126
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
127
|
+
*
|
|
128
|
+
* @publicApi
|
|
129
|
+
*/
|
|
130
|
+
export interface ConstructorProvider extends ConstructorSansProvider {
|
|
131
|
+
/**
|
|
132
|
+
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
|
133
|
+
*/
|
|
134
|
+
provide: Type<any>;
|
|
135
|
+
/**
|
|
136
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
137
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
138
|
+
*/
|
|
139
|
+
multi?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Configures the `Injector` to return a value of another `useExisting` token.
|
|
143
|
+
*
|
|
144
|
+
* @see `ExistingProvider`
|
|
145
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
146
|
+
*
|
|
147
|
+
* @publicApi
|
|
148
|
+
*/
|
|
149
|
+
export interface ExistingSansProvider {
|
|
150
|
+
/**
|
|
151
|
+
* Existing `token` to return. (Equivalent to `injector.get(useExisting)`)
|
|
152
|
+
*/
|
|
153
|
+
useExisting: any;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Configures the `Injector` to return a value of another `useExisting` token.
|
|
157
|
+
*
|
|
158
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
159
|
+
*
|
|
160
|
+
* @usageNotes
|
|
161
|
+
*
|
|
162
|
+
* {@example core/di/ts/provider_spec.ts region='ExistingProvider'}
|
|
163
|
+
*
|
|
164
|
+
* ### Multi-value example
|
|
165
|
+
*
|
|
166
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
167
|
+
*
|
|
168
|
+
* @publicApi
|
|
169
|
+
*/
|
|
170
|
+
export interface ExistingProvider extends ExistingSansProvider {
|
|
171
|
+
/**
|
|
172
|
+
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
|
173
|
+
*/
|
|
174
|
+
provide: any;
|
|
175
|
+
/**
|
|
176
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
177
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
178
|
+
*/
|
|
179
|
+
multi?: boolean;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Configures the `Injector` to return a value by invoking a `useFactory` function.
|
|
183
|
+
*
|
|
184
|
+
* @see `FactoryProvider`
|
|
185
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
186
|
+
*
|
|
187
|
+
* @publicApi
|
|
188
|
+
*/
|
|
189
|
+
export interface FactorySansProvider {
|
|
190
|
+
/**
|
|
191
|
+
* A function to invoke to create a value for this `token`. The function is invoked with
|
|
192
|
+
* resolved values of `token`s in the `deps` field.
|
|
193
|
+
*/
|
|
194
|
+
useFactory: Function;
|
|
195
|
+
/**
|
|
196
|
+
* A list of `token`s to be resolved by the injector. The list of values is then
|
|
197
|
+
* used as arguments to the `useFactory` function.
|
|
198
|
+
*/
|
|
199
|
+
deps?: any[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Configures the `Injector` to return a value by invoking a `useFactory` function.
|
|
203
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
204
|
+
*
|
|
205
|
+
* @usageNotes
|
|
206
|
+
*
|
|
207
|
+
* {@example core/di/ts/provider_spec.ts region='FactoryProvider'}
|
|
208
|
+
*
|
|
209
|
+
* Dependencies can also be marked as optional:
|
|
210
|
+
*
|
|
211
|
+
* {@example core/di/ts/provider_spec.ts region='FactoryProviderOptionalDeps'}
|
|
212
|
+
*
|
|
213
|
+
* ### Multi-value example
|
|
214
|
+
*
|
|
215
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
216
|
+
*
|
|
217
|
+
* @publicApi
|
|
218
|
+
*/
|
|
219
|
+
export interface FactoryProvider extends FactorySansProvider {
|
|
220
|
+
/**
|
|
221
|
+
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
222
|
+
*/
|
|
223
|
+
provide: any;
|
|
224
|
+
/**
|
|
225
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
226
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
227
|
+
*/
|
|
228
|
+
multi?: boolean;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Describes how an `Injector` should be configured as static (that is, without reflection).
|
|
232
|
+
* A static provider provides tokens to an injector for various types of dependencies.
|
|
233
|
+
*
|
|
234
|
+
* @see `Injector.create()`.
|
|
235
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection-providers).
|
|
236
|
+
*
|
|
237
|
+
* @publicApi
|
|
238
|
+
*/
|
|
239
|
+
export declare type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider | any[];
|
|
240
|
+
/**
|
|
241
|
+
* Configures the `Injector` to return an instance of `Type` when `Type' is used as the token.
|
|
242
|
+
*
|
|
243
|
+
* Create an instance by invoking the `new` operator and supplying additional arguments.
|
|
244
|
+
* This form is a short form of `TypeProvider`;
|
|
245
|
+
*
|
|
246
|
+
* For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
|
|
247
|
+
*
|
|
248
|
+
* @usageNotes
|
|
249
|
+
*
|
|
250
|
+
* {@example core/di/ts/provider_spec.ts region='TypeProvider'}
|
|
251
|
+
*
|
|
252
|
+
* @publicApi
|
|
253
|
+
*/
|
|
254
|
+
export interface TypeProvider extends Type<any> {
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Configures the `Injector` to return a value by invoking a `useClass` function.
|
|
258
|
+
* Base for `ClassProvider` decorator.
|
|
259
|
+
*
|
|
260
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
261
|
+
*
|
|
262
|
+
* @publicApi
|
|
263
|
+
*/
|
|
264
|
+
export interface ClassSansProvider {
|
|
265
|
+
/**
|
|
266
|
+
* Class to instantiate for the `token`.
|
|
267
|
+
*/
|
|
268
|
+
useClass: Type<any>;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Configures the `Injector` to return an instance of `useClass` for a token.
|
|
272
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
273
|
+
*
|
|
274
|
+
* @usageNotes
|
|
275
|
+
*
|
|
276
|
+
* {@example core/di/ts/provider_spec.ts region='ClassProvider'}
|
|
277
|
+
*
|
|
278
|
+
* Note that following two providers are not equal:
|
|
279
|
+
*
|
|
280
|
+
* {@example core/di/ts/provider_spec.ts region='ClassProviderDifference'}
|
|
281
|
+
*
|
|
282
|
+
* ### Multi-value example
|
|
283
|
+
*
|
|
284
|
+
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
|
|
285
|
+
*
|
|
286
|
+
* @publicApi
|
|
287
|
+
*/
|
|
288
|
+
export interface ClassProvider extends ClassSansProvider {
|
|
289
|
+
/**
|
|
290
|
+
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
291
|
+
*/
|
|
292
|
+
provide: any;
|
|
293
|
+
/**
|
|
294
|
+
* When true, injector returns an array of instances. This is useful to allow multiple
|
|
295
|
+
* providers spread across many files to provide configuration information to a common token.
|
|
296
|
+
*/
|
|
297
|
+
multi?: boolean;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Describes how the `Injector` should be configured.
|
|
301
|
+
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
302
|
+
*
|
|
303
|
+
* @see `StaticProvider`
|
|
304
|
+
*
|
|
305
|
+
* @publicApi
|
|
306
|
+
*/
|
|
307
|
+
export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
|
|
308
|
+
/**
|
|
309
|
+
* Describes a function that is used to process provider lists (such as provider
|
|
310
|
+
* overrides).
|
|
311
|
+
*/
|
|
312
|
+
export declare type ProcessProvidersFunction = (providers: Provider[]) => Provider[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from "../interface/type";
|
|
9
|
+
/**
|
|
10
|
+
* An interface that a function passed into {@link forwardRef} has to implement.
|
|
11
|
+
*
|
|
12
|
+
* @usageNotes
|
|
13
|
+
* ### Example
|
|
14
|
+
*
|
|
15
|
+
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref_fn'}
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
export interface ForwardRefFn {
|
|
19
|
+
(): any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Allows to refer to references which are not yet defined.
|
|
23
|
+
*
|
|
24
|
+
* For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of
|
|
25
|
+
* DI is declared, but not yet defined. It is also used when the `token` which we use when creating
|
|
26
|
+
* a query is not yet defined.
|
|
27
|
+
*
|
|
28
|
+
* @usageNotes
|
|
29
|
+
* ### Example
|
|
30
|
+
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
|
|
31
|
+
* @publicApi
|
|
32
|
+
*/
|
|
33
|
+
export declare function forwardRef(forwardRefFn: ForwardRefFn): Type<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Lazily retrieves the reference value from a forwardRef.
|
|
36
|
+
*
|
|
37
|
+
* Acts as the identity function when given a non-forward-ref value.
|
|
38
|
+
*
|
|
39
|
+
* @usageNotes
|
|
40
|
+
* ### Example
|
|
41
|
+
*
|
|
42
|
+
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
|
|
43
|
+
*
|
|
44
|
+
* @see `forwardRef`
|
|
45
|
+
* @publicApi
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveForwardRef<T>(type: T): T;
|
|
48
|
+
/** Checks whether a function is wrapped by a `forwardRef`. */
|
|
49
|
+
export declare function isForwardRef(fn: any): fn is () => any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { InjectFlags } from "./interface/injector";
|
|
9
|
+
import { ProviderToken } from "./provider_token";
|
|
10
|
+
/**
|
|
11
|
+
* Injects `root` tokens in limp mode.
|
|
12
|
+
*
|
|
13
|
+
* If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to
|
|
14
|
+
* `"root"`. This is known as the limp mode injection. In such case the value is stored in the
|
|
15
|
+
* injectable definition.
|
|
16
|
+
*/
|
|
17
|
+
export declare function injectRootLimpMode<T>(token: ProviderToken<T>, notFoundValue: T | undefined, flags: InjectFlags): T | null;
|