| OLD | NEW |
| (Empty) | |
| 1 library di.static_injector; |
| 2 |
| 3 import 'di.dart'; |
| 4 |
| 5 typedef Object TypeFactory(factory(Type)); |
| 6 |
| 7 /** |
| 8 * Static implementation of [Injector] that uses type factories |
| 9 */ |
| 10 class StaticInjector extends Injector { |
| 11 Map<Type, TypeFactory> typeFactories; |
| 12 |
| 13 StaticInjector({List<Module> modules, String name, |
| 14 bool allowImplicitInjection: false, this.typeFactories}) |
| 15 : super(modules: modules, name: name, |
| 16 allowImplicitInjection: allowImplicitInjection); |
| 17 |
| 18 StaticInjector._fromParent(List<Module> modules, Injector parent, {name}) |
| 19 : super.fromParent(modules, parent, name: name); |
| 20 |
| 21 newFromParent(List<Module> modules, String name) { |
| 22 return new StaticInjector._fromParent(modules, this, name: name); |
| 23 } |
| 24 |
| 25 Object newInstanceOf(Type type, ObjectFactory getInstanceByType, |
| 26 Injector requestor, error) { |
| 27 TypeFactory typeFactory = (root as StaticInjector).typeFactories[type]; |
| 28 if (typeFactory == null) { |
| 29 throw new NoProviderError(error('No type factory provided for $type!')); |
| 30 } |
| 31 return typeFactory((type) => getInstanceByType(type, requestor)); |
| 32 } |
| 33 } |
| OLD | NEW |