Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Circular Reference issue with Swift Suspenders #11

Closed
tschneidereit opened this issue Dec 4, 2009 · 4 comments
Closed

Circular Reference issue with Swift Suspenders #11

tschneidereit opened this issue Dec 4, 2009 · 4 comments

Comments

@tschneidereit
Copy link
Owner

(copied from http://github.com/robotlegs/robotlegs-framework/issues/#issue/1)

There is a circular reference bug if you have singletons that inject eachother.

Trivial example (Flex Builder 3 AS3 project) here: http://www.stevensacks.net/xfer/circbug.zip

And the output:

undefined

at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at org.swiftsuspenders::Injector/instantiate()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:134]
at org.swiftsuspenders.injectionresults::InjectSingletonResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectSingletonResult.as:59]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]

@benjamincombes
Copy link

Same problem for me :
TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:111]
at org.swiftsuspenders.injectionresults::InjectValueResult/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionresults/InjectValueResult.as:48]
at org.swiftsuspenders::InjectionConfig/getResponse()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/InjectionConfig.as:58]
at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:47]
at org.swiftsuspenders::Injector/injectInto()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/SwiftSuspenders/src/org/swiftsuspenders/Injector.as:120]
at fr.benjamincombes.toolbox.configuration::DefaultToolboxInjectorConfiguration/mapDependencies()[/Users/Ben/Documents/Travail/Projets/Toolbox/Toolbox/src/fr/benjamincombes/toolbox/configuration/DefaultToolboxInjectorConfiguration.as:53]
at fr.benjamincombes.toolbox::Toolbox$/init()[/Users/Ben/Documents/Travail/Projets/Toolbox/Toolbox/src/fr/benjamincombes/toolbox/Toolbox.as:26]
at TestRunningApplication/onCreationComplete()[/Users/Ben/Documents/Travail/Projets/Toolbox/Toolbox/tests/TestRunningApplication.mxml:21]
at TestRunningApplication/___TestRunningApplication_Application1_creationComplete()[/Users/Ben/Documents/Travail/Projets/Toolbox/Toolbox/tests/TestRunningApplication.mxml:7]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
Tell me if you source code may help you !

@tschneidereit
Copy link
Owner Author

That's actually a different problem not related to what this ticket is about.

Without having any source code, I can't be sure, but my guess would be that the specific bug you're running into has been fixed in the 1.5b1 release (and maybe even in the 1.0.1 release). Can you add the SWC from the latest zip distribution to your projects and check if the problem is resolved by that?
http://github.com/tschneidereit/SwiftSuspenders/downloads

@katopz
Copy link

katopz commented Jan 5, 2011

vote for this bug, any work around for this btw? i'm feeling dead here

@tschneidereit
Copy link
Owner Author

Having thought about it for quite some time, I don't think there's any feasible way to fix this.

The thing is that circular dependencies are just inherently broken: Both objects need each other to work in a way that the IoC container can't resolve by itself. In theory, a sub-set of cases could in fact be detected and resolved automatically, but I can't come up with a clean and performant implementation of even those.

A future version of SwiftSuspenders will support two things that should help to resolve this, though: optional and live injections. With optional injections, the injector doesn't throw if it can't fulfill a dependency, while with live injections, it will update the injectee as soon as the mapped value it expects changes. With these in place, I should be able to not only detect but also resolve cases of mutually recursive dependencies.

This issue was closed.
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants