How to make sure the right singleton gets injected in a loaded module context?

Weyert's Avatar


10 Oct, 2011 01:40 PM

I am having troubles with the injection of singleton (mapSingletonOf()) in the module contexts. The problem is that the first time it works correctly but the second time the services gets injected correctly in the shell class but when I then want to inject the same singleton in a loaded SWF file it still uses the old instance and not the new one.

Does anyone know why this could happen?

  1. Support Staff 1 Posted by Till Schneidere... on 10 Oct, 2011 01:47 PM

    Till Schneidereit's Avatar

    Can you describe what "the right singleton" means, exactly? Should all
    module contexts share their parent's singleton, or should they all
    have their own instance?

  2. 2 Posted by Weyert on 10 Oct, 2011 02:10 PM

    Weyert's Avatar

    The problem I am having is that I am have a class called SequenceContext in the shell application which deals with the playing a bunch of child SWFs. After all these child SWFs are played. The SequenceContext will unmap the injections created by startup() when shutdown() gets called.

    After the SHUTDOWN_COMPLETE event is dispatched the shell application instantiates a new instance of the SequenceContext and then new mappings are created. Now if I inject my singleton in a command of the SequenceContext it uses the correct instance. Only in the SWF file loaded by this SequenceContext its using the older instance. I am confused why :(

    At the moment of a bunch of trial-and-error the mapping doesn't exists anymore. While it all worked fine for the first instantiated SequenceContext.

  3. 3 Posted by Weyert on 10 Oct, 2011 02:15 PM

    Weyert's Avatar

    If I check via breakpoints the injector variable attendedToInjectees field does have multiple entries for the same class:

    nl.sequence::LanguageService@90b4d41    true    
    nl.sequence::LanguageService@91bef61    true

    Could this cause problems? I expected it had unmapped the injection???

  4. Support Staff 4 Posted by Till Schneidere... on 10 Oct, 2011 02:22 PM

    Till Schneidereit's Avatar

    Interesting problem ;)

    I'm afraid I can't be of much help without seeing some kind of a
    test-case. Ideally, that would be a reduced case that exposes the
    problem, but if you'd be willing to send me your source by private
    mail, I could also offer to take a look at your that, guaranteeing
    non-disclosure, of course. In that case, please add information about
    how to reproduce the symptoms in a debugger.

  5. 5 Posted by Weyert on 10 Oct, 2011 02:30 PM

    Weyert's Avatar

    Do you happen to have Skype?

  6. 6 Posted by simon on 10 Oct, 2011 02:34 PM

    simon's Avatar

    Maybe a wild guess here but I have a sneaky suspicion your re-loading cached SWF's?

    If this is the case the I would check your clear up within the actual module. So on unloading your modules I would first call (unless you already are) a destroy() method within your module which will run a rampage throughout the module clearing up all references. Then call the Shell to unload the module....

  7. Support Staff 7 Posted by Till Schneidere... on 10 Oct, 2011 03:25 PM

    Till Schneidereit's Avatar

    Weyert and I discussed the problem over Skype and it looks like it
    might be related to passing a wrong Injector into the modules.

  8. 8 Posted by Weyert on 10 Oct, 2011 09:44 PM

    Weyert's Avatar

    I have found the solution. I was injecting the main injector instance of the shell application into the loaded module. This was causing trouble in paradise. Moved the view factory a few levels down and it started the work. A view here represents different content types (video, images, swf, module [swf with dynamic data support]).

    Tomorrow, I will spend the morning to do regression testing. But I am having a good feeling the problem is solved now. Phew. That took a long time! Thanks all for your help ('rubber duck debugging' ;-)

  9. Weyert closed this discussion on 10 Oct, 2011 09:44 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac