dart-archive / di.dart

DEPRECATED
https://webdev.dartlang.org/angular/guide/dependency-injection
MIT License
65 stars 57 forks source link

Comments to getByKey method #228

Open acherepanov opened 8 years ago

acherepanov commented 8 years ago

In this piece of code in lib/src/injector.dart do you mean An alternative could be to recurse only when parent is not a RootInjector instead of An alternative could be to recurse only when parent is not a ModuleInjector?

    Binding binding = _bindings[id];
    // When binding is null, recurse instead of iterate because it:
    // 1. tracks key history on the stack for error reporting
    // 2. allows different types of ancestor injectors with alternative implementations.
    // An alternative could be to recurse only when parent is not a ModuleInjector
    if (binding == null) return _instances[id] = parent.getByKey(key);

When parent is a RootInjector, getByKey immediately throws exception, but in ModuleInjector this method works fine.