perf: switch angular to use StaticInjector instead of ReflectiveInjector

This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.

Code savings for HelloWorld using Closure:

Reflective: bundle.js:  105,864(34,190 gzip)
    Static: bundle.js:  154,889(33,555 gzip)
                            645( 2%)

BREAKING CHANGE:

`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.

Example:
Before:
```
[
  MyClass,
  {provide: ClassA, useClass: SubClassA}
]

```

After:
```
[
  {provide: MyClass, deps: [Dep1,...]},
  {provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```

NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.

Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.

DEPRECATION:

- `ReflectiveInjector` is now deprecated as it will be remove. Use
  `Injector.create` as a replacement.

closes #18496
This commit is contained in:
Miško Hevery
2017-08-03 12:33:29 -07:00
committed by Victor Berchet
parent d9d00bd9b5
commit fcadbf4bf6
94 changed files with 380 additions and 279 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ReflectiveInjector} from '@angular/core';
import {Injector} from '@angular/core';
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {BrowserJsonp} from '../../src/backends/browser_jsonp';
@ -52,10 +52,10 @@ export function main() {
let sampleRequest: Request;
beforeEach(() => {
const injector = ReflectiveInjector.resolveAndCreate([
{provide: ResponseOptions, useClass: BaseResponseOptions},
{provide: BrowserJsonp, useClass: MockBrowserJsonp},
{provide: JSONPBackend, useClass: JSONPBackend_}
const injector = Injector.create([
{provide: ResponseOptions, useClass: BaseResponseOptions, deps: []},
{provide: BrowserJsonp, useClass: MockBrowserJsonp, deps: []},
{provide: JSONPBackend, useClass: JSONPBackend_, deps: [BrowserJsonp, ResponseOptions]}
]);
backend = injector.get(JSONPBackend);
const base = new BaseRequestOptions();

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ReflectiveInjector} from '@angular/core';
import {Injector} from '@angular/core';
import {AsyncTestCompleter, beforeEach, describe, inject, it, xit} from '@angular/core/testing/src/testing_internal';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ReplaySubject} from 'rxjs/ReplaySubject';
@ -27,8 +27,10 @@ export function main() {
let sampleResponse2: Response;
beforeEach(() => {
const injector = ReflectiveInjector.resolveAndCreate(
[{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
const injector = Injector.create([
{provide: ResponseOptions, useClass: BaseResponseOptions, deps: []},
{provide: MockBackend, deps: []}
]);
backend = injector.get(MockBackend);
const base = new BaseRequestOptions();
sampleRequest1 =

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injector, ReflectiveInjector} from '@angular/core';
import {Injector} from '@angular/core';
import {TestBed, getTestBed} from '@angular/core/testing';
import {AsyncTestCompleter, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {expect} from '@angular/platform-browser/testing/src/matchers';
@ -79,8 +79,8 @@ export function main() {
let jsonp: Jsonp;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
BaseRequestOptions, MockBackend, {
injector = Injector.create([
{provide: BaseRequestOptions, deps: []}, {provide: MockBackend, deps: []}, {
provide: Http,
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);

View File

@ -114,7 +114,7 @@ export class MockConnection implements Connection {
* ### Example
*
* ```
* import {Injectable, ReflectiveInjector} from '@angular/core';
* import {Injectable, Injector} from '@angular/core';
* import {async, fakeAsync, tick} from '@angular/core/testing';
* import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '@angular/http';
* import {Response, ResponseOptions} from '@angular/http';
@ -142,7 +142,7 @@ export class MockConnection implements Connection {
*
* describe('MockBackend HeroService Example', () => {
* beforeEach(() => {
* this.injector = ReflectiveInjector.resolveAndCreate([
* this.injector = Injector.create([
* {provide: ConnectionBackend, useClass: MockBackend},
* {provide: RequestOptions, useClass: BaseRequestOptions},
* Http,
@ -202,7 +202,7 @@ export class MockBackend implements ConnectionBackend {
* ### Example
*
* ```
* import {ReflectiveInjector} from '@angular/core';
* import {Injector} from '@angular/core';
* import {fakeAsync, tick} from '@angular/core/testing';
* import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '@angular/http';
* import {Response, ResponseOptions} from '@angular/http';
@ -213,7 +213,7 @@ export class MockBackend implements ConnectionBackend {
* MockConnection; // this will be set when a new connection is emitted from the
* // backend.
* let text: string; // this will be set from mock response
* let injector = ReflectiveInjector.resolveAndCreate([
* let injector = Injector.create([
* {provide: ConnectionBackend, useClass: MockBackend},
* {provide: RequestOptions, useClass: BaseRequestOptions},
* Http,