refactor(core): separate reflective injector from Injector interface

BREAKING CHANGE:
- Injector was renamed into `ReflectiveInjector`,
  as `Injector` is only an abstract class with one method on it
- `Injector.getOptional()` was changed into `Injector.get(token, notFoundValue)`
  to make implementing injectors simpler
- `ViewContainerRef.createComponent` now takes an `Injector`
  instead of `ResolvedProviders`. If a reflective injector
  should be used, create one before calling this method.
  (e.g. via `ReflectiveInjector.resolveAndCreate(…)`.
This commit is contained in:
Tobias Bosch
2016-04-14 12:35:24 -07:00
parent efbd446d18
commit 0a7d10ba55
46 changed files with 1790 additions and 1719 deletions

View File

@ -1,4 +1,4 @@
import {Injectable, Injector, Key, bind, provide} from "angular2/core";
import {Injectable, ReflectiveInjector, ReflectiveKey, bind, provide} from "angular2/core";
import {reflector} from 'angular2/src/core/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
import {getIntParameter, bindAction, microBenchmark} from 'angular2/src/testing/benchmark_util';
@ -17,10 +17,10 @@ export function main() {
// This benchmark does not use bootstrap and needs to create a reflector
setupReflector();
var bindings = [A, B, C, D, E];
var injector = Injector.resolveAndCreate(bindings);
var injector = ReflectiveInjector.resolveAndCreate(bindings);
var D_KEY = Key.get(D);
var E_KEY = Key.get(E);
var D_KEY = ReflectiveKey.get(D);
var E_KEY = ReflectiveKey.get(E);
var childInjector = injector.resolveAndCreateChild([])
.resolveAndCreateChild([])
.resolveAndCreateChild([])
@ -29,7 +29,7 @@ export function main() {
var variousProviders = [A, provide(B, {useClass: C}), [D, [E]], provide(F, {useValue: 6})];
var variousProvidersResolved = Injector.resolve(variousProviders);
var variousProvidersResolved = ReflectiveInjector.resolve(variousProviders);
function getByToken() {
for (var i = 0; i < iterations; ++i) {
@ -63,7 +63,7 @@ export function main() {
*/
function createVariety() {
for (var i = 0; i < iterations; ++i) {
Injector.resolveAndCreate(variousProviders);
ReflectiveInjector.resolveAndCreate(variousProviders);
}
}
@ -72,7 +72,7 @@ export function main() {
*/
function createVarietyResolved() {
for (var i = 0; i < iterations; ++i) {
Injector.fromResolvedProviders(variousProvidersResolved);
ReflectiveInjector.fromResolvedProviders(variousProvidersResolved);
}
}