EventDispatcher not being injected: eventDispatcher = null
Hi there!
First of all, I think this is a remarkable framework. I've been
following it's evolution for some time and - wow - the work you've
done on it in such a short time is really amazing. The docs and
examples are great and it's easy to grasp the concepts of Robotlegs
by reading them. And - Robotlegs!!! How can you resist a framework
with such a cool name! 8]
Ok, now the second thing I'd like to talk about is I'm having a
little problem with eventDispatcher being null in my service class.
I'm using swc v.0.9.5, compiling with flex sdk in FDT3.
The code looks like this, nothing much:
var swfAddressService:SwfAddressService = new SwfAddressService();
injector.mapValue(SwfAddressService, swfAddressService);
swfAddressService.initialize();
Now, after swfAddressService initializes, it receives CHANGE
event from SWFAddress and should pass it to the system like
so:
protected function onAddressChanged(e:SWFAddressEvent):void
{
eventDispatcher.dispatchEvent(e);
}
But, the eventDispatcher is null there. Does it look like
injection problem or should i be doing some more stuff?
Thanks ;]
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Joel Hooks on 29 Oct, 2009 11:25 PM
In your case you need to manually fire that injection:
because you are manually creating the instance, you need to manually inject the dependencies. The eventDispatcher property will be available immediately.3 Posted by hush on 29 Oct, 2009 11:48 PM
Fantastic, thanks for the fast reply ;]
Support Staff 4 Posted by Till Schneidereit on 30 Oct, 2009 10:57 AM
Or, to be sure that all eventual injection points are dealt with, you could use
var swfAddressService:SwfAddressService =
injector.instantiate(SwfAddressService);
and be done with it.
5 Posted by hush on 30 Oct, 2009 11:10 AM
Great, even more elegant for my case. Thanks a lot! ;]
Till Schneidereit closed this discussion on 30 Oct, 2009 11:18 AM.
hush re-opened this discussion on 28 Nov, 2009 11:28 PM
6 Posted by hush on 28 Nov, 2009 11:28 PM
Ok, I'm getting back to this again. (Now using v1.0 swc)
If I write the following code in my StartupCommand:
and later inject flashvars in another command
then Flashvars gets constructed twice. Is that a normal behaviour?
PS Congratulations with v1.0, yoohoooo, nice work ;]
Support Staff 7 Posted by Shaun Smith on 28 Nov, 2009 11:46 PM
Interesting. No, that doesn't seem right. I suspect it's a bit of an edge-case, as you're mapping to an interface and then depending on a class (roughly speaking). Could you try:
8 Posted by hush on 28 Nov, 2009 11:58 PM
Same result, gets constructed twice :P
9 Posted by hush on 29 Nov, 2009 12:05 AM
I certainly can write like this and it works:
But something tells me that injector.instantiate should also have worked.
Support Staff 10 Posted by Till Schneidereit on 30 Nov, 2009 12:59 AM
Can you check if you get two different instances of the singletons in
your injectees? I'm guessing that you don't and everything is working
as it should (or as best as it can). There's a bug in the Flash Player
that forces SwiftSuspenders (and every other DI solution supporting
constructor injection) to create one throw-away instance of each class
it should instantiate. For more information, see this bug in the Flash
Player issue tracker: http://bugs.adobe.com/jira/browse/FP-183
11 Posted by Jos Yule on 07 Dec, 2009 02:41 AM
If i can also make a suggestion.
One trick that i have been using (i'm pretty sure via Joel H), is to create a Command to setup your Model/Service. So, in your context do something like:
Then, in your
SetupFlashvarsCommand:That makes sure that all your dependiancies are taken care of (in your flashvars class, assuming you've used the
[Inject]tag around them.Help? Hinder?
Support Staff 12 Posted by Shaun Smith on 07 Dec, 2009 03:37 PM
That's a good approach. One small thing: the mvcs abstract command already has a reference to the contextView, so no need to declare it again (I think it would throw an error anyway).
13 Posted by xisari on 15 Dec, 2009 12:13 PM
Maybe I'm a few days too late but here is my suggestion:
The mapSingleton() command creates an instance of your class and you create an additional one with injector.instantiate(Flashvars)
You should either create the instance via mapSingleton() and use a command to push the data into it (like Jos suggested) or you create the instance in the context und push the data there.
Shaun Smith closed this discussion on 06 Jan, 2010 11:54 PM.