Strategy patterns wired via robot legs

visnik's Avatar


07 Mar, 2012 05:08 PM

I am thinking about creating some strategy patterns to deal with some service and parsing classes and implement them with the RL framework. I have looked at the following two posts here and here . One mentions switching at runtime, I just need it at compile time so I don’t think I need the info posted by ZackPierce. In the other post Stray mentions the following:

Personally I do like to have multiple services that implement the same interface and have a base service class for the common functionality. It does depend what your service does though. Generally I'm talking about an ILoadingService and then DogLoadingService CatLoadingService etc that extend BaseAnimalLoadingService.

This is what I was thinking, though not really using a base or abstract class, but could if that is the better approach.

Simple question is how do I map each implementation of the interface in the context so the correct concrete class is used via dependency injection in my actor, or command etc?


  1. 1 Posted by Paul Robertson on 07 Mar, 2012 06:12 PM

    Paul Robertson's Avatar

    I think what you're looking for is:

    injector.mapSingletonOf(IServiceInterface, ConcreteService);

    If it's a small app you might be doing all the mappings in one context file.

    For larger apps I break the mappings into "modular" pieces using configuration commands (there are several posts on this forum about how to do that). In that case, all the mappings for one implementation versus the other one would go in different config commands, and you could just change one event mapping in the main config/context to determine which of those config commands gets executed.


  2. 2 Posted by visnik on 07 Mar, 2012 08:58 PM

    visnik's Avatar

    Thanks for your reply, Though I might be misunderstanding your reply, so my apologies for my ignorance, however let me give a semi-concrete example of what I am trying to do.

    Let’s say I have an interface called IApplicationService, and I have two classes that implement IApplicationService, ConcreateServiceOne and ConcreteSeriviceTwo. Without RL I would do the following within lets say my ConcreteCommand class:

    Public var impelemntationOne: IApplicationService = new ConcreateServiceOne();
    Public var impelemntationTwo: IApplicationService = new ConcreateServiceTwo();
    //Elsewhere in my code…

    My question is with robot legs, would I do something like the following:
    In my context, or wherever I bootstrap…

    Injector. mapClass(IApplicationService, ConcreateServiceOne, impelemntationOne);
    Injector. mapClass(IApplicationService, ConcreateServiceTwo, impelemntationTwo);

    And within my RL ConcreteCommand class:

    [Inject] public var impelemntationOne: IApplicationService;
    [Inject] public var impelemntationTwo: IApplicationService;
    //Elsewhere in my code…

    Now I am not sure if this is the proper use of the 3rd parameter in the mapClass method, or proper implementation. Or if use of the mapRule method, is better for this, and if so, how do I use that? This I guess is what I am looking for guidance through the murky swamp.


  3. Support Staff 3 Posted by Ondina D.F. on 10 Mar, 2012 12:29 PM

    Ondina D.F.'s Avatar

    Hi visnik,

    If you map them like this:

    injector.mapClass(IApplicationService, ConcreateServiceOne, „impelemntationOne“);
    injector.mapClass(IApplicationService, ConcreateServiceTwo, „impelemntationTwo“);

    impelemntationOne and impelemntationTwo are Strings.

    Then, you’ll have to use named injections, like this:

    [Inject (name="impelemntationOne")] public var impelemntationOne:IApplicationService;

    [Inject (name="impelemntationTwo")] public var anotherImplementation:IApplicationService;


    Note: the variables’ names don’t matter. What matters is the 3rd parameter in your mapping (named:String)

    injector.mapClass(IApplicationService, ConcreateServiceOne, „impelemntationOne“);

    which corresponds to:
    [Inject (name="impelemntationOne")]


  4. 4 Posted by visnik on 14 Mar, 2012 12:00 AM

    visnik's Avatar

    Thanks again Ondina.

  5. Support Staff 5 Posted by Ondina D.F. on 19 Mar, 2012 08:40 AM

    Ondina D.F.'s Avatar

    You're welcome!

  6. Ondina D.F. closed this discussion on 19 Mar, 2012 08:40 AM.

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