tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/845-strategy-patterns-wired-via-robot-legsRobotlegs: Discussion 2012-03-19T08:40:05Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/143067142012-03-07T18:12:35Z2012-03-07T18:12:35ZStrategy patterns wired via robot legs<div><p>I think what you're looking for is:</p>
<p>injector.mapSingletonOf(IServiceInterface, ConcreteService);</p>
<p>If it's a small app you might be doing all the mappings in one
context file.</p>
<p>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.</p>
<p>Paul</p></div>Paul Robertsontag:robotlegs.tenderapp.com,2009-10-18:Comment/143067142012-03-07T20:58:52Z2012-03-07T20:58:52ZStrategy patterns wired via robot legs<div><p>Paul,<br>
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.</p>
<p>Let’s say I have an interface called
<em>IApplicationService</em>, and I have two classes that implement
<em>IApplicationService</em>, <em>ConcreateServiceOne</em> and
<em>ConcreteSeriviceTwo</em>. Without RL I would do the following
within lets say my <em>ConcreteCommand</em> class:</p>
<pre>
<code>Public var impelemntationOne: IApplicationService = new ConcreateServiceOne();
Public var impelemntationTwo: IApplicationService = new ConcreateServiceTwo();
//Elsewhere in my code…
impelemntationOne.doSomthing();
impelemntationTwo.doSomthing();</code>
</pre>
<p>My question is with robot legs, would I do something like the
following:<br>
In my context, or wherever I bootstrap…</p>
<pre>
<code>Injector. mapClass(IApplicationService, ConcreateServiceOne, impelemntationOne);
Injector. mapClass(IApplicationService, ConcreateServiceTwo, impelemntationTwo);</code>
</pre>
<p>And within my RL <em>ConcreteCommand</em> class:</p>
<pre>
<code>[Inject] public var impelemntationOne: IApplicationService;
[Inject] public var impelemntationTwo: IApplicationService;
//Elsewhere in my code…
impelemntationOne.doSomthing();
impelemntationTwo.doSomthing();</code>
</pre>
<p>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.</p>
<p>Thanks,</p></div>visniktag:robotlegs.tenderapp.com,2009-10-18:Comment/143067142012-03-10T12:29:56Z2012-03-13T22:38:13ZStrategy patterns wired via robot legs<div><p>Hi visnik,</p>
<p>If you map them like this:</p>
<p>injector.mapClass(IApplicationService, ConcreateServiceOne,
„impelemntationOne“);<br>
injector.mapClass(IApplicationService, ConcreateServiceTwo,
„impelemntationTwo“);</p>
<p>impelemntationOne and impelemntationTwo are Strings.</p>
<p>Then, you’ll have to use named injections, like this:</p>
<p>[Inject (name="impelemntationOne")] public var
impelemntationOne:IApplicationService;</p>
<p>[Inject (name="impelemntationTwo")] public var
anotherImplementation:IApplicationService;</p>
<p>impelemntationOne.doSomthing();<br>
anotherImplementation.doSomthing();</p>
<p>Note: the variables’ names don’t matter. What
matters is the 3rd parameter in your mapping (named:String)</p>
<p>injector.mapClass(IApplicationService, ConcreateServiceOne,
„impelemntationOne“);</p>
<p>which corresponds to:<br>
[Inject (name="impelemntationOne")]</p>
<p>HTH</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/143067142012-03-14T00:00:59Z2012-03-14T00:00:59ZStrategy patterns wired via robot legs<div><p>Thanks again Ondina.</p></div>visniktag:robotlegs.tenderapp.com,2009-10-18:Comment/143067142012-03-19T08:40:04Z2012-03-19T08:40:04ZStrategy patterns wired via robot legs<div><p>You're welcome!</p></div>Ondina D.F.