Mediators no longer available for injection with RL v1.1.0
I was wondering if the documentation that's on the site is still valid for the 1.1.1 version and I just wanted to check I was doing the right thing as I'm getting an injection error that doesn't show up in 1.0.3.
Thanks.
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Joel Hooks on 14 Jul, 2010 04:58 PM
you'll need to be more specific.
Support Staff 3 Posted by Shaun Smith on 14 Jul, 2010 05:03 PM
Hi Foodlove,
v1.1.x should be fully backwards compatible with v1.0.x - if something in your app has broken simply due to upgrading from v1.0.3 to v1.1.1 then we'd have to look into that. Could you provide any more details? You can switch this discussion to "private" (right hand side of page) if you'd like to.
4 Posted by foodlove on 14 Jul, 2010 05:13 PM
I'm getting the "Injector is missing a rule to handle injection into
target".
I have a command which relies on a mediator being available.
I know the mediator is instantiated because its onRegister function is
called.
However when the command that uses/needs the mediator is run I get the
error:
Injector is missing a rule to handle injection into target...
My mediator is mapped to my view before that command gets called, but I
can't see what's wrong. When I switch back to the 1.0.3 version the problem
goes away.
I initially thought it might be a life cycle issue, display objects being
created a while after the command gets called, but it seems to be ok in
1.0.3.
5 Posted by foodlove on 14 Jul, 2010 05:24 PM
i'm using Flex 4 by the way.
Support Staff 6 Posted by Joel Hooks on 14 Jul, 2010 05:26 PM
The documentation is still valid. Shaun might know the mechanics of why this is broken for you now. Usually it revolves around the fixing of a bug. I do know that mediators are not mapped for injection, so unless you are mapping it yourself, it shouldn't get injected to the command at all.
It is considered best practice to send the mediator events from the command that needs to talk to a mediator.
Support Staff 7 Posted by Shaun Smith on 14 Jul, 2010 05:29 PM
Aha! I see what's happening there. You can read the backstory here:
http://knowledge.robotlegs.org/faqs/framework-core/why-cant-i-injec...
Essentially it boils down to this: it worked for you with v1.0.3 because of a side-effect. The automatic mediation process no longer leaves temporary mappings lying around.
To regain your old behavior you'll need to explicitly tell the injector about the mediator that you want available for injection. You could probably do this in your mediator's onRegister hook, something like this:
// Inject the Injector [Inject] public var injector:IInjector; override public function onRegister():void { // throw this instance into the Injector injector.mapValue(ThisMediator, this); }Or, you could do the mapping elsewhere.
As Joel mentioned though, and as explained in the link above, injecting Mediators is not recommended - it's usually better to fire off an event that the mediator can respond too.
Hope that helps!
8 Posted by foodlove on 14 Jul, 2010 05:35 PM
Ok, that makes sense. I think i'll go with Joel's suggestion and also read the documentation properly ; )
Thanks for responding quickly and building a great framework.
Support Staff 9 Posted by Shaun Smith on 14 Jul, 2010 05:37 PM
Cool, no probs. As this thread might be useful to others, I'd like to edit the title (to: "Mediators no longer available for injection with RL v1.1.0"), remove the project specific traces from post 4, and switch this discussion back to PUBLIC. Would that be OK with you?
10 Posted by foodlove on 14 Jul, 2010 05:39 PM
no problem at all.
11 Posted by geoff on 23 Dec, 2010 12:09 AM
Thanks for this post! I used the above technique to inject a property inside one of my mediator classes:
injector.mapValue(CloseButton, closeButton);
It worked great, but is it ok to inject things into the framework inside a mediator class? Is this why I had to 'inject my injector' before I could do this?
What's the best practice here?
Stray closed this discussion on 13 Feb, 2011 03:41 PM.