tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/153-array-configurationinjectionRobotlegs: Discussion 2013-04-28T09:57:12Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762010-08-20T20:56:11Z2010-08-20T20:56:11ZArray Configuration/Injection <div><p>we need a lot more detail:)</p></div>Nikos tag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762010-08-21T12:01:47Z2010-08-21T12:01:48ZArray Configuration/Injection <div><p>basically I pretty much need this scenario:<br />
<a href="http://www.herrodius.com/blog/136">http://www.herrodius.com/blog/136</a><br />
I need a way to configure the factory with the parsers inside it.</p>
<p>10x.<br />
Claudiu</p></div>claudiutag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762010-08-21T16:16:07Z2010-08-21T16:16:07ZArray Configuration/Injection <div><p>Hi, I don't understand the question, and I don't see how it relates to Robotlegs?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762010-08-22T09:34:18Z2010-08-22T09:34:19ZArray Configuration/Injection <div><p>Sorry if I am not being explicit enough.<br />
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.</p>
<pre><code> var exerciseFactory:ExerciseFactory = new ExerciseFactory();
exerciseFactory.addParser(new MultipleChoiceDialectAParser());
exerciseFactory.addParser(new MultipleChoiceDialectBParser());
exerciseFactory.addParser(new FillGapsDialectAParser());</code></pre>
<p>with Spring As this code is configure like this:</p>
<p><br />
<object class="ExerciseFactory"></p>
<pre><code><constructor-arg>
<array>
<object class="MultipleChoiceDialectAParser"/>
<object class="MultipleChoiceDialectBParser"/>
<object class="FillGapsDialectAParser"/>
</array>
</constructor-arg></code></pre>
<p> </object>
</p>
<p>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?</p>
<p>Hope this makes sense.<br />
10x,<br />
Claudiu</p></div>claudiutag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762010-08-31T08:51:16Z2010-08-31T08:51:18ZArray Configuration/Injection <div><p>I left this aside for a while due to low priority but ultimately I went ahead went this:</p>
<p>Context/Command</p>
<p>var parsers:Array = injector.instantiate(Array);<br />
parsers.push(injector.instantiate(CustomParser1));<br />
parsers.push(injector.instantiate(CustomParser3));<br />
parsers.push(injector.instantiate(CustomParser3));<br />
injector.mapValue(Array, parsers, "parsers");</p>
<p>factory class:</p>
<p>[Inject(name="parsers")] <br />
public class FactoryClass<br />
{</p>
<pre><code>private var _parsers:Array;
public function MessageParserFactory(parsers:Array)
{
_parsers = parsers;
}</code></pre>
<p>}</p>
<p>Seems to do the trick. Anyone knows a better way of doing this if any ?<br />
10x,<br />
Claudiu</p>
<p>It's a shame though you cannot inject Vectors instead of Arrays. Anyone knows when that will be possible?</p></div>claudiutag:robotlegs.tenderapp.com,2009-10-18:Comment/26435762011-02-10T17:43:20Z2011-02-10T17:43:20ZArray Configuration/Injection <div><p>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.</p>
<p>Always, always avoid injecting the base classes.</p></div>Stray