jasperblues/Typhoon — pull request #78 by cesteban (2013-09-12 18:04:37+00:00)
Title: Currently resolving overwrite

Tentative fix for #77: Instead of storing currently resolving references in a plain dictionary, we store it in a dictionary of stacks (more or less hidden behind TyphoonInstanceRegister abstraction). This means if we are currently resolving a reference, and one of the dependencies involved in the same cycle needs to instantiate the component again, then instead of overwriting the instance in the dictionary, we store it in the top of its local stack. Then, markDefinitionAsAlreadyresolved consumes the top of the stack instead of nilifying the dictionary entry. This way, all the dependencies are receiving their correct local instance during circular injection, and we never inject nil.

I know Jasper is concerned about init injection of circular dependencies, it is not what he had in mind, and I agree it is a source of problems. However, this feature is being incredibly useful to me, and I don't want to stop using it unless I really have to. And at any case, while we support it, we need to properly manage it.

I would love to hear your opinion on this.