Skip to content

Dead loop when 2 singleton injectee reference each other #173

@7ujian

Description

@7ujian

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions