tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/690-how-to-make-sure-the-right-singleton-gets-injected-in-a-loaded-module-contextRobotlegs: Discussion 2018-10-18T16:35:32Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T13:47:13Z2011-10-10T13:47:13ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>Can you describe what "the right singleton" means, exactly?
Should all<br>
module contexts share their parent's singleton, or should they
all<br>
have their own instance?</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T14:10:55Z2011-10-10T14:10:55ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>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.</p>
<p>After the <code>SHUTDOWN_COMPLETE</code> event is dispatched the
shell application instantiates a new instance of the
<code>SequenceContext</code> and then new mappings are created. Now
if I inject my singleton in a command of the
<code>SequenceContext</code> it uses the correct instance. Only in
the SWF file loaded by this <code>SequenceContext</code> its using
the older instance. I am confused why :(</p>
<p>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
<code>SequenceContext</code>.</p></div>Weyerttag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T14:15:35Z2011-10-10T14:15:35ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>If I check via breakpoints the injector variable
attendedToInjectees field does have multiple entries for the same
class:</p>
<pre>
<code>nl.sequence::LanguageService@90b4d41 true
nl.sequence::LanguageService@91bef61 true</code>
</pre>
<p>Could this cause problems? I expected it had unmapped the
injection???</p></div>Weyerttag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T14:22:18Z2011-10-10T14:22:18ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>Interesting problem ;)</p>
<p>I'm afraid I can't be of much help without seeing some kind of
a<br>
test-case. Ideally, that would be a reduced case that exposes
the<br>
problem, but if you'd be willing to send me your source by
private<br>
mail, I could also offer to take a look at your that,
guaranteeing<br>
non-disclosure, of course. In that case, please add information
about<br>
how to reproduce the symptoms in a debugger.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T14:30:42Z2011-10-10T14:30:42ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>Do you happen to have Skype?</p></div>Weyerttag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T14:34:33Z2011-10-10T14:39:56ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>Maybe a wild guess here but I have a sneaky suspicion your
re-loading cached SWF's?</p>
<p>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....</p></div>simontag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T15:25:20Z2011-10-10T15:25:20ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>Weyert and I discussed the problem over Skype and it looks like
it<br>
might be related to passing a wrong Injector into the modules.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/105201432011-10-10T21:44:16Z2011-10-10T21:44:16ZHow to make sure the right singleton gets injected in a loaded module context?<div><p>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]).</p>
<p>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'
;-)</p></div>Weyert