tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/4363-mapping-servicesRobotlegs: Discussion 2013-09-23T14:40:55Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/280276522013-08-02T16:39:30Z2013-08-02T16:39:30ZMapping Services <div><p>Hi Harold,</p>
<p>I'm truly sorry for the delay in responding!<br>
It looks like each of us, support staffers, has been busy.</p>
<p>Very nice diagrams :)</p>
<p>I'd prefer to have separate commands for different actions (
print, load something, save something).</p>
<p>My advice is to avoid having a single command that has to decide
which service to use ( probably depending on some kind of flag from
the signal's payload), especially when there are more than 2
services. You'll end up having long switch/if statements in your
execute method, and depending on how you map your services, you
might need to inject several services into one command, whilst you
actually need just one of them at a time.</p>
<p>Alternatively, you could inject a dictionary or a collection of
your choice into your command, that contains the services. It is
just an idea, I haven't tried it out yet. I'll have to think about
it a little more to see whether it's a good approach or not, or
whether I'd used it in my commands.</p>
<p>Mappings</p>
<pre>
<code>var toolService:ToolSocketService = injector.getOrCreateNewInstance(ToolSocketService);
var printService:PrintSocketService = injector.getOrCreateNewInstance(PrintSocketService);
services["print"] = printService;
services["tool"] = toolService;
injector.map(Dictionary, "services").toValue(services);</code>
</pre>
<p>Command</p>
<pre>
<code>[Inject (name="services")]
public var services:Dictionary;</code>
</pre>
<pre>
<code>public function execute():void
{
services[vo.service].connect();
}</code>
</pre>
<p>vo.service is the VO that the signal carries.</p>
<p>Btw, how are you currently mapping your services and how are you
injecting them into commands?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/280276522013-08-03T10:51:08Z2013-08-03T10:51:08ZMapping Services <div><p>Hi Ondina,<br>
Thx for the answer, everybody is in holidays? :-)<br>
No problem for the delay, It's enable me to search by myself
solutions, and the project maturate.</p>
<p>I like your second solution, injecting dictionary into command.
I will try it!<br>
Finally the stuff I'm looking for is a kind of polymorphism
mechanism?<br>
To enable the possibility to map a service depending on the type of
the value object.</p>
<p>During this few days I have discovered some pretty things like
extensions and bundles.<br>
My idea is to have 2 different contexts (PrinterContext and
ToolContext) with different mappings. I began to write an
SocketServiceExtension but I don't know where to put my
classes...<br>
I know there is 3 packages (api, dsl, impl) but where I can put my
classes correctly I don't.</p>
<p>I do this tree :<br></p>
<pre>
<code>+ socketService
- SocketServiceExtension
+ api
- ISocketService
+ dsl
- SocketServiceEvent
- SocketServiceRequestEvent
- ISocketDevice
+ impl
- AbstractSocketService
- ConnectDeviceCommand
- DisconnectDeviceCommand
- SendDatasToDeviceCommand</code>
</pre>
I think I'm not right but I don't know what I should to put in the
extension and what I should to put in my bundle...</div>harold.martintag:robotlegs.tenderapp.com,2009-10-18:Comment/280276522013-08-03T13:35:17Z2013-08-03T13:35:17ZMapping Services <div><p>Hey Harold,</p>
<p>Are you sure you want to create an extension for your abstract
service and commands, or your intention was to have a library
shared between different contexts, where you put the common
classes?</p>
<p>If you <strong>really</strong> want to have an extension, then,
I think, you'd have to create some sort of a SocketServiceMap,
where you add the services and/or commands and map them in
there.</p>
<pre>
<code>public class SocketServiceExtension implements IExtension
{
public function extend(context:IContext):void
{
context.injector.map(IServiceSocketMap).toType(ServiceSocketMap);
}
}</code>
</pre>
<p>After you install your extension in each context, you inject
IServiceSocketMap into a config file and you call something
like:</p>
<pre>
<code>serviceSocketMap.addService("print", PrintSocketService);
serviceSocketMap.addService("tool", ToolSocketService);
serviceSocketMap.mapServices();</code>
</pre>
<p>where the first parameter would be the key in your services
dictionary, and the second the service class you need in that
particular context.</p>
<p>So, your extension would contain only the "shared" classes and
would be used just to wire things together.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/280276522013-08-05T11:51:15Z2013-08-05T12:04:08ZMapping Services <div><p>Hi Ondina,<br>
I'm not sure I understand the main purpose of extensions... Yes I
don't need extension but only a shared library.</p>
<p>I've work hard to write this library this weekend, and it's time
to share my work :-)</p>
<p>I try some examples, and it seems to work correctly.</p>
<p>Attached you can find :<br></p>
<pre>
<code>- RobotlegsSignalCommandMapExtension.swc (SignalCommandMapExtension compatible with robotlegs v2.1.0)
- SocketServiceLib.zip (sources + swc)
- SocketServiceLibDiagram.png (The classes diagramm of SocketServiceLib)</code>
</pre>
Can you tell me what you thing about this.
<p>Thx a lot.</p></div>harold.martintag:robotlegs.tenderapp.com,2009-10-18:Comment/280276522013-08-05T14:53:11Z2013-08-05T14:53:11ZMapping Services <div><p>Hey Harold,</p>
<p>I had a quick look at your lib.<br>
Yes, I can see that you put a lot of work into it!<br>
It looks very good, so far :)</p>
<p>Ondina</p></div>Ondina D.F.