2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. 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.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-09 13:49:16 -08:00
|
|
|
import {Type} from '../../interface/type';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value for a token.
|
2019-06-10 10:04:11 -07:00
|
|
|
* Base for `ValueProvider` decorator.
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface ValueSansProvider {
|
|
|
|
|
/**
|
|
|
|
|
* The value to inject.
|
|
|
|
|
*/
|
|
|
|
|
useValue: any;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 23:17:05 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value for a token.
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2016-09-14 09:43:01 -07:00
|
|
|
* ### Example
|
2015-04-15 22:35:38 +00:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='ValueProvider' linenums="false"}
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2015-04-09 23:17:05 -07:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface ValueProvider extends ValueSansProvider {
|
2017-07-27 13:49:33 -07:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
2017-07-27 13:49:33 -07:00
|
|
|
*/
|
|
|
|
|
provide: any;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2017-07-27 13:49:33 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
|
|
|
|
*/
|
|
|
|
|
multi?: boolean;
|
|
|
|
|
}
|
2015-04-15 22:35:38 +00:00
|
|
|
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return an instance of `useClass` for a token.
|
2019-06-10 10:04:11 -07:00
|
|
|
* Base for `StaticClassProvider` decorator.
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface StaticClassSansProvider {
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* An optional class to instantiate for the `token`. By default, the `provide`
|
|
|
|
|
* class is instantiated.
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
useClass: Type<any>;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* A list of `token`s to be resolved by the injector. The list of values is then
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
* used as arguments to the `useClass` constructor.
|
|
|
|
|
*/
|
|
|
|
|
deps: any[];
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 19:37:42 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return an instance of `useClass` for a token.
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2017-07-27 13:49:33 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='StaticClassProvider'}
|
|
|
|
|
*
|
|
|
|
|
* Note that following two providers are not equal:
|
2018-05-18 16:13:00 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='StaticClassProviderDifference' linenums="false"}
|
2016-09-14 09:43:01 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2016-08-15 19:37:42 -07:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface StaticClassProvider extends StaticClassSansProvider {
|
2015-04-15 22:35:38 +00:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
provide: any;
|
2015-04-15 22:35:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2016-08-15 19:37:42 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
multi?: boolean;
|
|
|
|
|
}
|
2015-04-15 22:35:38 +00:00
|
|
|
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
/**
|
2018-05-18 16:13:00 +01:00
|
|
|
* Configures the `Injector` to return an instance of a token.
|
|
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2018-05-18 16:13:00 +01:00
|
|
|
*
|
2018-04-05 09:58:02 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* ```ts
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
* @Injectable(SomeModule, {deps: []})
|
|
|
|
|
* class MyService {}
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface ConstructorSansProvider {
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* A list of `token`s to be resolved by the injector.
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
deps?: any[];
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 19:37:42 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return an instance of a token.
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='ConstructorProvider' linenums="false"}
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2016-08-15 19:37:42 -07:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface ConstructorProvider extends ConstructorSansProvider {
|
2015-04-15 22:35:38 +00:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2017-07-27 13:49:33 -07:00
|
|
|
provide: Type<any>;
|
2015-04-15 22:35:38 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2016-08-15 19:37:42 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
multi?: boolean;
|
2015-04-09 23:17:05 -07:00
|
|
|
}
|
|
|
|
|
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value of another `useExisting` token.
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see `ExistingProvider`
|
|
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2019-06-10 10:04:11 -07:00
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface ExistingSansProvider {
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* Existing `token` to return. (Equivalent to `injector.get(useExisting)`)
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
useExisting: any;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-10 22:11:13 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value of another `useExisting` token.
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2015-12-03 15:49:09 -08:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='ExistingProvider' linenums="false"}
|
2016-08-15 19:37:42 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2015-10-10 22:11:13 -07:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface ExistingProvider extends ExistingSansProvider {
|
2015-10-12 11:30:34 -07:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
|
2015-10-12 11:30:34 -07:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
provide: any;
|
2015-10-12 11:30:34 -07:00
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2016-08-15 19:37:42 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
2015-10-12 11:30:34 -07:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
multi?: boolean;
|
2015-10-10 22:11:13 -07:00
|
|
|
}
|
2015-09-17 13:12:50 -07:00
|
|
|
|
2015-04-09 23:17:05 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value by invoking a `useFactory` function.
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see `FactoryProvider`
|
|
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2015-04-17 03:29:05 -07:00
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
2018-05-18 16:13:00 +01:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface FactorySansProvider {
|
2015-04-15 22:35:38 +00:00
|
|
|
/**
|
2016-08-15 19:37:42 -07:00
|
|
|
* A function to invoke to create a value for this `token`. The function is invoked with
|
|
|
|
|
* resolved values of `token`s in the `deps` field.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
useFactory: Function;
|
2014-09-30 14:56:33 -04:00
|
|
|
|
2015-04-15 22:35:38 +00:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* A list of `token`s to be resolved by the injector. The list of values is then
|
2016-08-15 19:37:42 -07:00
|
|
|
* used as arguments to the `useFactory` function.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-24 12:53:28 -07:00
|
|
|
deps?: any[];
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value by invoking a `useFactory` function.
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='FactoryProvider' linenums="false"}
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
|
|
|
|
* Dependencies can also be marked as optional:
|
2018-05-18 16:13:00 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='FactoryProviderOptionalDeps' linenums="false"}
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface FactoryProvider extends FactorySansProvider {
|
|
|
|
|
/**
|
|
|
|
|
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
|
|
|
*/
|
|
|
|
|
provide: any;
|
2015-02-21 15:18:06 +01:00
|
|
|
|
2015-04-15 22:35:38 +00:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2016-08-15 19:37:42 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
2015-04-15 22:35:38 +00:00
|
|
|
*/
|
2016-08-15 19:37:42 -07:00
|
|
|
multi?: boolean;
|
2015-04-09 23:17:05 -07:00
|
|
|
}
|
2014-09-30 14:56:33 -04:00
|
|
|
|
2017-07-27 13:49:33 -07:00
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* Describes how the `Injector` should be configured as static (that is, without reflection).
|
|
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2017-07-27 13:49:33 -07:00
|
|
|
*/
|
|
|
|
|
export type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider |
|
|
|
|
|
ConstructorProvider | FactoryProvider | any[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return an instance of `Type` when `Type' is used as the token.
|
2017-07-27 13:49:33 -07:00
|
|
|
*
|
|
|
|
|
* Create an instance by invoking the `new` operator and supplying additional arguments.
|
|
|
|
|
* This form is a short form of `TypeProvider`;
|
|
|
|
|
*
|
2018-05-18 12:19:29 +01:00
|
|
|
* For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
|
2017-07-27 13:49:33 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='TypeProvider' linenums="false"}
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2017-07-27 13:49:33 -07:00
|
|
|
*/
|
|
|
|
|
export interface TypeProvider extends Type<any> {}
|
|
|
|
|
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return a value by invoking a `useClass` function.
|
2019-06-10 10:04:11 -07:00
|
|
|
* Base for `ClassProvider` decorator.
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
*/
|
|
|
|
|
export interface ClassSansProvider {
|
|
|
|
|
/**
|
|
|
|
|
* Class to instantiate for the `token`.
|
|
|
|
|
*/
|
|
|
|
|
useClass: Type<any>;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-27 13:49:33 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Configures the `Injector` to return an instance of `useClass` for a token.
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2017-07-27 13:49:33 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @usageNotes
|
2019-06-10 10:04:11 -07:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='ClassProvider' linenums="false"}
|
2017-07-27 13:49:33 -07:00
|
|
|
*
|
|
|
|
|
* Note that following two providers are not equal:
|
2018-05-18 16:13:00 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='ClassProviderDifference' linenums="false"}
|
2017-07-27 13:49:33 -07:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* ### Multi-value example
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2019-07-01 12:31:42 -07:00
|
|
|
* {@example core/di/ts/provider_spec.ts region='MultiProviderAspect' linenums="false"}
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2017-07-27 13:49:33 -07:00
|
|
|
*/
|
feat: change @Injectable() to support tree-shakeable tokens (#22005)
This commit bundles 3 important changes, with the goal of enabling tree-shaking
of services which are never injected. Ordinarily, this tree-shaking is prevented
by the existence of a hard dependency on the service by the module in which it
is declared.
Firstly, @Injectable() is modified to accept a 'scope' parameter, which points
to an @NgModule(). This reverses the dependency edge, permitting the module to
not depend on the service which it "provides".
Secondly, the runtime is modified to understand the new relationship created
above. When a module receives a request to inject a token, and cannot find that
token in its list of providers, it will then look at the token for a special
ngInjectableDef field which indicates which module the token is scoped to. If
that module happens to be in the injector, it will behave as if the token
itself was in the injector to begin with.
Thirdly, the compiler is modified to read the @Injectable() metadata and to
generate the special ngInjectableDef field as part of TS compilation, using the
PartialModules system.
Additionally, this commit adds several unit and integration tests of various
flavors to test this change.
PR Close #22005
2018-02-02 10:33:48 -08:00
|
|
|
export interface ClassProvider extends ClassSansProvider {
|
2017-07-27 13:49:33 -07:00
|
|
|
/**
|
|
|
|
|
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
|
|
|
*/
|
|
|
|
|
provide: any;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* When true, injector returns an array of instances. This is useful to allow multiple
|
2017-07-27 13:49:33 -07:00
|
|
|
* providers spread across many files to provide configuration information to a common token.
|
|
|
|
|
*/
|
|
|
|
|
multi?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 10:21:28 -07:00
|
|
|
/**
|
2018-04-05 10:32:04 +01:00
|
|
|
* Describes how the `Injector` should be configured.
|
2019-07-01 12:31:42 -07:00
|
|
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
2018-04-05 10:16:31 +01:00
|
|
|
*
|
2018-05-18 16:13:00 +01:00
|
|
|
* @see `StaticProvider`
|
2018-10-19 16:27:04 +01:00
|
|
|
*
|
|
|
|
|
* @publicApi
|
2015-09-02 10:21:28 -07:00
|
|
|
*/
|
2018-05-09 16:49:39 -07:00
|
|
|
export type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider |
|
|
|
|
|
ExistingProvider | FactoryProvider | any[];
|
2019-03-11 10:35:25 -07:00
|
|
|
|
|
|
|
|
/**
|
2019-07-01 12:31:42 -07:00
|
|
|
* Describes a function that is used to process provider lists (such as provider
|
2019-03-11 10:35:25 -07:00
|
|
|
* overrides).
|
|
|
|
|
*/
|
2019-07-02 23:57:02 +03:00
|
|
|
export type ProcessProvidersFunction = (providers: Provider[]) => Provider[];
|