Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Dead loop when 2 singleton injectee reference each other #173

Open
7ujian opened this issue Jan 5, 2015 · 0 comments
Open

Dead loop when 2 singleton injectee reference each other #173

7ujian opened this issue Jan 5, 2015 · 0 comments

Comments

@7ujian
Copy link

7ujian commented Jan 5, 2015

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant