tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/883-inject-abstractmodelRobotlegs: Discussion 2012-05-14T12:04:20Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/154677862012-04-24T12:43:38Z2012-04-24T12:43:38ZInject AbstractModel<div><p>Hi Kimak,</p>
<p>I’m not sure I understand how you are mapping the models
and commands.<br>
It sounds like you are mapping the models in the context of each
module, and the CommonCommand in the shell’s context. Then
you want to trigger the same command from each module?<br>
Later on you mention a Module1Command , which lets me think there
is a Module2Command as well. Are you mapping them in the
shell’s context or within each module’s context?</p>
<p>Anyway, if you had<br>
2 Commands SharedCommandOne and SharedCommandTwo, both mapped in
the shell’s context and 2 Models, SharedModelOne and
SharedModelTwo, also mapped in the shell’s context, both
extending AbstractModel, then you can use <em>named injection</em>
to distinguish one Model from another:</p>
<p>
injector.mapSingletonOf(AbstractModel,SharedModelOne,"modelOne");<br>
injector.mapSingletonOf(AbstractModel,SharedModelTwo,"modelTwo");</p>
<p>
moduleCommandMap.mapEvent(SharedEvent.OPEN_SHARED_COMMAND_ONE,SharedCommandOne);<br>
moduleCommandMap.mapEvent(SharedEvent.OPEN_SHARED_COMMAND_TWO,SharedCommandTwo);</p>
<p>SharedCommandOne:</p>
<p>[Inject (name="modelOne")]</p>
<p>public var model:AbstractModel;</p>
<p>SharedCommandTwo:</p>
<p>[Inject (name="modelTwo")]</p>
<p>public var model:AbstractModel;</p>
<p>Would this work for you?</p>
<blockquote>
<p>Did you have any options to Inject a class with two different
type on different commands? Or this is a SwiftSuspender limitation
?</p>
</blockquote>
<p>A mapping like this:<br>
injector.mapSingletonOf(AbstractModel, Module1Model);<br>
injector.mapSingletonOf(AbstractModel, Module2Model);</p>
<p>is ambiguous. The first injection would be overwritten by the
second one. The injector can not know what to inject into what and
when. Named injections let the injector distinguish between the 2
mappings.<br>
Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/154677862012-04-24T13:43:57Z2012-04-24T13:43:57ZInject AbstractModel<div><p>And in case you want to avoid named injections, you can use
something like this:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/questions/590-using-mult">
http://knowledge.robotlegs.org/discussions/questions/590-using-mult</a>...</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/154677862012-05-09T20:14:55Z2012-05-09T20:14:55ZInject AbstractModel<div><p>I choose the wrapper solution on your link, to avoid named
injections.</p>
<p>Thank you for the answer !</p></div>Kimaktag:robotlegs.tenderapp.com,2009-10-18:Comment/154677862012-05-14T12:04:18Z2012-05-14T12:04:18ZInject AbstractModel<div><p>No problem:)</p></div>Ondina D.F.