feat(di): provide two ways to create an injector, resolved and unresolved
Add two factory static functions to Injector: resolveAndCreate and fromResolvedBindings. We want to avoid resolution and flattening every time we create a new injector. This commit allows the user to cache resolved bindings and reuse them.
This commit is contained in:
4
modules/angular2/src/core/application.js
vendored
4
modules/angular2/src/core/application.js
vendored
@ -276,10 +276,10 @@ export function bootstrap(appComponentType: Type,
|
||||
}
|
||||
|
||||
function _createAppInjector(appComponentType: Type, bindings: List<Binding>, zone: VmTurnZone): Injector {
|
||||
if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings);
|
||||
if (isBlank(_rootInjector)) _rootInjector = Injector.resolveAndCreate(_rootBindings);
|
||||
var mergedBindings = isPresent(bindings) ?
|
||||
ListWrapper.concat(_injectorBindings(appComponentType), bindings) :
|
||||
_injectorBindings(appComponentType);
|
||||
ListWrapper.push(mergedBindings, bind(VmTurnZone).toValue(zone));
|
||||
return _rootInjector.createChild(mergedBindings);
|
||||
return _rootInjector.resolveAndCreateChild(mergedBindings);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ export class DynamicComponentLoader {
|
||||
|
||||
_componentAppInjector(location, injector, services) {
|
||||
var inj = isPresent(injector) ? injector : location.injector;
|
||||
return isPresent(services) ? inj.createChild(services) : inj;
|
||||
return isPresent(services) ? inj.resolveAndCreateChild(services) : inj;
|
||||
}
|
||||
|
||||
_instantiateAndHydrateView(protoView, injector, hostElementInjector, context) {
|
||||
|
2
modules/angular2/src/core/compiler/view.js
vendored
2
modules/angular2/src/core/compiler/view.js
vendored
@ -153,7 +153,7 @@ export class AppView {
|
||||
if (isPresent(componentDirective)) {
|
||||
var injectables = componentDirective.annotation.injectables;
|
||||
if (isPresent(injectables))
|
||||
shadowDomAppInjector = appInjector.createChild(injectables);
|
||||
shadowDomAppInjector = appInjector.resolveAndCreateChild(injectables);
|
||||
else {
|
||||
shadowDomAppInjector = appInjector;
|
||||
}
|
||||
|
Reference in New Issue
Block a user