tschneidereit / SwiftSuspenders

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders
https://github.com/robotlegs/swiftsuspenders
MIT License
280 stars 89 forks source link

Child ApplicationDomains break the injector #33

Open fakeasanything opened 13 years ago

fakeasanything commented 13 years ago

We created a RobotLegs SWF (with SwiftSuspenders) and it worked fine standalone. However, when loading this into another Robotlegs SWF (also with SwiftSuspenders) in a child ApplicationDomain at runtime, injection failed in the child SWF, throwing the following exception:

Exception fault: ReferenceError: Error #1065: Variable MyClassView is not defined. at flash.system::ApplicationDomain/getDefinition() at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/initializeInjection()[/Users/tschneidereit/dev/swiftsuspenders/swiftsuspenders/src/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as:58]

So it seems that when a RobotLegs SWF using SwiftSuspenders loads another RobotLegs SWF using SwiftSuspenders in a child ApplicationDomain, injection breaks completely - it seems as though SwiftSuspenders is using the injector/injection settings from the parent domain?

Loading the SWF into the same ApplicationDomain does work, however this does open up other problems for us. We can use this as a workaround for now, but it would be great to find out whether we're doing something wrong, or whether this is an issue with SwiftSuspenders (or indeed RobotLegs). Our investigation has led us to believe this is an issue with SwiftSuspenders.

Is anyone familiar with this problem?

Hope someone can help,

Mani

Matan commented 13 years ago

Hi Mani,

I had the same problem ( http://github.com/tschneidereit/SwiftSuspenders/issues#issue/31 ) and like you said passing the "current" application domain solves the problem, but if you need to have the child in it's own app domain it fails.

Don't currently know of any fixes for this. :(

fakeasanything commented 13 years ago

Cheers Matan!

Fingers crossed someone can shed some light on this!

Mani

vizio360 commented 13 years ago

Hi guys,

I did load an external robotlegs module in a child Application Domain and it worked.

e.g. in the mainApp: load external SWF which is a RobotLegs Module passing a new LoaderContext with a child domain of the current ApplicationDomain. var childDomain:ApplicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); var context:LoaderContext = new LoaderContext(false, childDomain); Once the module has loaded you need to pass through the parent injector, which is the injector of the mainAppContext.

In the RobotLegs Module you then pass the following to the constructor of the ModuleContext: context = new YourContext(this, true, rootInjector, ApplicationDomain.currentDomain); In this case ApplicationDomain.currentDomain refers to the currentDomain of the swf which is the childDomain we passed in the LoaderContext. So now your robotlegs module is in its own ApplicationDomain, even though it's a child domain of the mainApp ApplicationDomain. In this way the Robotlegs module can access the class definitions specified in the mainApp ApplicationDomain.

It worked for us, now we load external Robotlegs modules with no issues.

darscan commented 12 years ago

ping