you shouldn't re-inject an object at runtime. We don't support that work flow at all.
This is one of the reasons that we don't advise injecting other things into Mediators - just their view.
In the next version (1.6) of Robotlegs (out within the next week or so) you can't inject Mediators into other objects at all - it was something that was an accidental by product of how the mediator mappings were carried out.
You should fire an event from your mediator which you pick up in the Command and send to the service. And your service should fire an event (or a model should, after update by the service) which the mediator picks up to give the result to the view.
So - unfortunately the answer is "Don't inject services into your Mediator". Timing issues like these are part of the reason why we advise against it.
The alternative is that you use a Service locator ... which is a very un-Robotlegs way to do things, but would work.
If you're absolutely sold on not changing things, then the following code in your command would achieve what you want...
public var theMediator:TheMediator;
override public function execute():void
var serviceInstance:ISearchService = injector.getInstance(ISearchService);
theMediator.searchService = serviceInstance;
However - this will mean you can't update to the next version of Robotlegs when it comes out.
But you should really just try out the events approach - it's very, very reliable.
That's just what I wanted to hear! :-) I did feel that it wasn't
very clean to inject the mediator, I just couldn't come up with
anything that seemed more logical.
However, I'm not quite sure I understand your solution. What I
intended was simply to swap the TwitterSearchService
and OtherSearchService in the mapping of
ISearchService, because I thought it better than doing some sort of
conditional (in the mediator that requests data) against a model;
if (someModel.service == "twitter")
else if (someModel.service == "other")
I'm not sure I'm explaining myself right here, but I hope you
get the idea.
Is the unmapping and remapping of a new class not the way at
all? To me it seems incredibly simple and clean, and the "only"
thing missing is the updating of the mediator.