Using multiple Interfaces for services

patricklemiuex's Avatar


19 Jun, 2011 07:14 PM

Love robotlegs! K. I am trying to use multiple services with interfaces for my application, for instance, I have an AMF remoting service and a JSON service. Say for instance, whichever service I need is a property in a proxy. What's the cleanest way to map my service "on demand" so I can use multiple services if necessary?

Can you provide a simple example please.


  1. Support Staff 1 Posted by Stray on 19 Jun, 2011 07:30 PM

    Stray's Avatar

    Hi Patrick,

    just checking - do you mean you want to switch the JSON / AMF / whatever service at runtime?


  2. 2 Posted by patricklemiuex on 19 Jun, 2011 07:40 PM

    patricklemiuex's Avatar


    Yes that's correct at runtime, depending which option is selected - i
    have advanced settings.

  3. 3 Posted by ZackPierce on 23 Jun, 2011 05:19 AM

    ZackPierce's Avatar

    Because re-injection into objects isn't currently supported in Robotlegs/SwiftSuspenders 1.X, it's less than straightforward to attempt to solve this by injection-mapping-switching on the fly, especially if any persistent (read non-Command) objects have lingering references to your service interface (I'm looking meaningfully in the direction of the mediators).

    So, one solution is to use a strategy pattern. Make an implementation of your service interface that delegates all of the real work to an implementation property. Then, use commands to swap your different AMF / JSON variant objects into that property on demand.

    interface IServiceExample {
        function doSomething():void;
    class WrapperServiceExample implements IServiceExample {
        public var implementation:IServiceExample;
        public function doSomething():void {
    // in the context
    var wrapper:WrapperServiceExample = injector.getInstance(WrapperServiceExample);
    injector.mapValue(IServiceExample, wrapper);
    class SwapToUsingAMFService extends Command {
        public var wrapper:WrapperServiceExample;
        public var amfService:AMFServiceExample;
        override public function execute():void {
            wrapper.implementation = amfService;
  4. Ondina D.F. closed this discussion on 02 Nov, 2011 05:22 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