dart-archive / di.dart

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

dynamic injector causes infinite loop #93

Closed vicb closed 10 years ago

vicb commented 10 years ago

see https://github.com/angular/angular.dart/issues/961

The problem seems to be in dynamic_injector.newInstanceOf() which has an infinite recursion in some cases.

vicb commented 10 years ago

The root cause of the issue in angular is in the element binder:

      probe = _expando[node] = new ElementProbe(
          parentInjector.get(ElementProbe), node, nodeInjector, scope);

The first arg of the ElementProbe ctor is the parent (ie an ElementProbe) this causes the infinite recursion. There must be something wrong in getting the parent injector in the newest DI ?

neermitt commented 10 years ago

The problem seems to be with Angular Internal Module registers ElementProb as null value. And by DI code logic instead of registering it as a Value dependency, it is registered as Type.

if (toValue != null) { _providers[key.id] = new ValueProvider(key.type, toValue, visibility); } else if (toFactory != null) { _providers[key.id] = new FactoryProvider(key.type, toFactory, visibility); } else { _providers[key.id] = new TypeProvider( toImplementation == null ? key.type : toImplementation, visibility); }

This results in this infinite search for the parent. Whereas the intention was that at root level Angular will supply fixed null value as ElementProbe so that when first ElementProbe is created it is created with null parent.

vicb commented 10 years ago

@neermitt :+1: you've found the root cause.

Could you please submit a PR to fix that ? (toValue arg should have a default value set to _EMPTY_VALUE = whatever const object and you should test for this value rather than testing for null).

vicb commented 10 years ago

It would be great to also add a unit test for that. Thanks.

pavelgj commented 10 years ago

PR with a fix #95

pavelgj commented 10 years ago

di version 0.0.40 pushed to pub