Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: third_party/pkg/di/lib/static_injector.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/pkg/di/lib/reflected_type.dart ('k') | third_party/pkg/di/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/pkg/di/lib/static_injector.dart
diff --git a/third_party/pkg/di/lib/static_injector.dart b/third_party/pkg/di/lib/static_injector.dart
index 71931005b8d318dacd74a3caf1deafcff7fa06cc..f7bf51f7e1c05a1672ac75e64f7de28cd7345844 100644
--- a/third_party/pkg/di/lib/static_injector.dart
+++ b/third_party/pkg/di/lib/static_injector.dart
@@ -2,8 +2,6 @@ library di.static_injector;
import 'di.dart';
-typedef Object TypeFactory(factory(Type));
-
/**
* Static implementation of [Injector] that uses type factories
*/
@@ -11,12 +9,16 @@ class StaticInjector extends Injector {
Map<Type, TypeFactory> typeFactories;
StaticInjector({List<Module> modules, String name,
- bool allowImplicitInjection: false, this.typeFactories})
+ bool allowImplicitInjection: false, typeFactories})
: super(modules: modules, name: name,
- allowImplicitInjection: allowImplicitInjection);
+ allowImplicitInjection: allowImplicitInjection) {
+ this.typeFactories = _extractTypeFactories(modules, typeFactories);
+ }
StaticInjector._fromParent(List<Module> modules, Injector parent, {name})
- : super.fromParent(modules, parent, name: name);
+ : super.fromParent(modules, parent, name: name) {
+ this.typeFactories = _extractTypeFactories(modules);
+ }
newFromParent(List<Module> modules, String name) {
return new StaticInjector._fromParent(modules, this, name: name);
@@ -24,10 +26,33 @@ class StaticInjector extends Injector {
Object newInstanceOf(Type type, ObjectFactory getInstanceByType,
Injector requestor, error) {
- TypeFactory typeFactory = (root as StaticInjector).typeFactories[type];
+ TypeFactory typeFactory = _getFactory(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;
+}
« no previous file with comments | « third_party/pkg/di/lib/reflected_type.dart ('k') | third_party/pkg/di/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698