| Index: third_party/pkg/di/lib/static_injector.dart
|
| ===================================================================
|
| --- third_party/pkg/di/lib/static_injector.dart (revision 33054)
|
| +++ third_party/pkg/di/lib/static_injector.dart (working copy)
|
| @@ -2,6 +2,8 @@
|
|
|
| import 'di.dart';
|
|
|
| +typedef Object TypeFactory(factory(Type));
|
| +
|
| /**
|
| * Static implementation of [Injector] that uses type factories
|
| */
|
| @@ -9,16 +11,12 @@
|
| Map<Type, TypeFactory> typeFactories;
|
|
|
| StaticInjector({List<Module> modules, String name,
|
| - bool allowImplicitInjection: false, typeFactories})
|
| + bool allowImplicitInjection: false, this.typeFactories})
|
| : super(modules: modules, name: name,
|
| - allowImplicitInjection: allowImplicitInjection) {
|
| - this.typeFactories = _extractTypeFactories(modules, typeFactories);
|
| - }
|
| + allowImplicitInjection: allowImplicitInjection);
|
|
|
| StaticInjector._fromParent(List<Module> modules, Injector parent, {name})
|
| - : super.fromParent(modules, parent, name: name) {
|
| - this.typeFactories = _extractTypeFactories(modules);
|
| - }
|
| + : super.fromParent(modules, parent, name: name);
|
|
|
| newFromParent(List<Module> modules, String name) {
|
| return new StaticInjector._fromParent(modules, this, name: name);
|
| @@ -26,33 +24,10 @@
|
|
|
| Object newInstanceOf(Type type, ObjectFactory getInstanceByType,
|
| Injector requestor, error) {
|
| - TypeFactory typeFactory = _getFactory(type);
|
| + TypeFactory typeFactory = (root as StaticInjector).typeFactories[type];
|
| if (typeFactory == null) {
|
| throw new NoProviderError(error('No type factory provided for $type!'));
|
| }
|
| return typeFactory((type) => getInstanceByType(type, requestor));
|
| }
|
| -
|
| - TypeFactory _getFactory(Type type) {
|
| - var cursor = this;
|
| - while (cursor != null) {
|
| - if (cursor.typeFactories.containsKey(type)) {
|
| - return cursor.typeFactories[type];
|
| - }
|
| - cursor = cursor.parent;
|
| - }
|
| - return null;
|
| - }
|
| -}
|
| -
|
| -Map<Type, TypeFactory> _extractTypeFactories(List<Module> modules,
|
| - [Map<Type, TypeFactory> initial = const {}]) {
|
| - if (modules == null || modules.isEmpty) return initial;
|
| - var tmp = new Map.from(initial == null ? {} : initial);
|
| - modules.forEach((module) {
|
| - module.typeFactories.forEach((type, factory) {
|
| - tmp[type] = factory;
|
| - });
|
| - });
|
| - return tmp;
|
| -}
|
| +}
|
|
|