When 2 singleton injectee reference each other. A dead loop is caused during injection.
Here is an example:
class A
{
[Inject] B;
}
class B
{
[Inject] A;
}
class Foo
{
public function Foo()
{
var injector:Injector = new Injector();
injector.map(A).asSingleton();
injector.map(B).asSingleton();
injector.getInstance(A);
}
}
A fixed is adding a "postInstantiate" callback in Injector before "applyInjectionPoints" and assign the instance to _response in the callback.
SingletonProvider.as
private function createResponse(injector : Injector) : Object
{
if (_destroyed)
{
throw new InjectorError("Forbidden usage of unmapped singleton provider for type "
+ getQualifiedClassName(_responseType));
}
return injector.instantiateUnmapped(_responseType, postInstantiate);
}
private function postInstantiate(instance : Object)
{
_response = instance;
}
When 2 singleton injectee reference each other. A dead loop is caused during injection.
Here is an example:
class A { [Inject] B; }
class B { [Inject] A; } class Foo { public function Foo() { var injector:Injector = new Injector(); injector.map(A).asSingleton(); injector.map(B).asSingleton(); injector.getInstance(A); }
}
A fixed is adding a "postInstantiate" callback in Injector before "applyInjectionPoints" and assign the instance to _response in the callback.
SingletonProvider.as