Array Configuration/Injection

claudiu's Avatar


20 Aug, 2010 01:56 PM

I need to inject an array with 3 elements object elements all of which implements the same interface.
Any idea how to do that?
Something like:

            <NestedObject id="one" 

            <NestedObject id="two" 

            <NestedObject id="three" 



  1. 1 Posted by Nikos on 20 Aug, 2010 08:56 PM

    Nikos 's Avatar

    we need a lot more detail:)

  2. 2 Posted by claudiu on 21 Aug, 2010 12:01 PM

    claudiu's Avatar

    basically I pretty much need this scenario:
    I need a way to configure the factory with the parsers inside it.


  3. Support Staff 3 Posted by Shaun Smith on 21 Aug, 2010 04:16 PM

    Shaun Smith's Avatar

    Hi, I don't understand the question, and I don't see how it relates to Robotlegs?

  4. 4 Posted by claudiu on 22 Aug, 2010 09:34 AM

    claudiu's Avatar

    Sorry if I am not being explicit enough.
    Basically I am using the same scenario. I have a factory and some parsing classes. the idea that each strategy class can decide is I am using if it can parse it's really neat. The thing Robotlegs to wire my application not Spring As or Parsely so I have no idea how I configure the factory class to be initialized with the parser.

      var exerciseFactory:ExerciseFactory = new ExerciseFactory();
      exerciseFactory.addParser(new MultipleChoiceDialectAParser());
      exerciseFactory.addParser(new MultipleChoiceDialectBParser());
      exerciseFactory.addParser(new FillGapsDialectAParser());

    with Spring As this code is configure like this:

        <object class="MultipleChoiceDialectAParser"/>
        <object class="MultipleChoiceDialectBParser"/>
        <object class="FillGapsDialectAParser"/>

    When you want to use it you just inject it into your client and that's it. The same goes for parsley only the syntax is more similar to my first post. How can I define the array than the 3 custom parsers inside it?

    Hope this makes sense.

  5. 5 Posted by claudiu on 31 Aug, 2010 08:51 AM

    claudiu's Avatar

    I left this aside for a while due to low priority but ultimately I went ahead went this:


    var parsers:Array = injector.instantiate(Array);
    injector.mapValue(Array, parsers, "parsers");

    factory class:

    public class FactoryClass

    private var _parsers:Array;
    public function MessageParserFactory(parsers:Array)
        _parsers = parsers;


    Seems to do the trick. Anyone knows a better way of doing this if any ?

    It's a shame though you cannot inject Vectors instead of Arrays. Anyone knows when that will be possible?

  6. Support Staff 6 Posted by Stray on 10 Feb, 2011 05:43 PM

    Stray's Avatar

    In these cases it's better to wrap your object in a VO - then you can have a Vector of the items rathe than just the array.

    Always, always avoid injecting the base classes.

  7. Stray closed this discussion on 10 Feb, 2011 05:43 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