tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/13227-mapping-multiple-types-to-same-singletonRobotlegs: Discussion 2015-10-20T17:04:55Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/382125412015-10-16T11:16:53Z2015-10-16T11:16:53ZMapping multiple types to same singleton<div><p>Hi Mike,</p>
<p>Do you want something similar to the viewProcessorMap?</p>
<p>viewProcessorMap.mapMatcher(new TypeMatcher().anyOf(ISpaceShip,
IRocket)).toProcessor(SpacecraftSkinner);</p>
<blockquote>
<p>_injector.mapAll(SGDialogEngine,
DialogEngine).toSingleton(SGDialogEngine);</p>
</blockquote>
<p>That's not possible, as far as I know. There is no mapAll in
Swiftsuspenders' Injector.<br>
You'd need to build your own extension that would add this
functionality....</p>
<p>Or just a simple method called mapAll which takes as arguments a
DependencyProvider and a collection of classes to be mapped:</p>
<pre>
<code>var clazzes:Array = [AnotherClass, IDrawThings, ICountThings, OtherClass];
var depProvider:DependencyProvider = injector.map(SomeClass).getProvider();
mapAll(clazzes, depProvider);
inside of mapAll you iterate over the clazzes and map them toProvider:
injector.map(clazzes[i]).toProvider(depProvider);</code>
</pre>
<p>Or, you can use the new Injector's method
<strong>toProviderOf</strong> instead of toProvider:</p>
<pre>
<code>injector.map(SomeClass).asSingleton();
var clazzes:Array = [AnotherClass, IDrawThings, ICountThings, OtherClass];
mapAll(clazzes, SomeClass);
injector.map(clazzes[i]).toProviderOf(someClass);</code>
</pre>
<p>Actually, in your example you are mapping a derived class and
the base class to the derived class. Is that right? Why do you need
to do that?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/382125412015-10-18T23:44:34Z2015-10-19T23:47:58ZMapping multiple types to same singleton<div><p>Hi Ondiana,</p>
<p>Thanks so much for getting back to me, really appreciated and
thanks for continuing support of RL, I have been using it for many
years, had a break for a little while but back again now, really
great to see someone continuing on supporting the community.</p>
<p>As for this problem. Yes I am mapping the base and derived class
to the same instance. The reason is because some parts of the code
rely upon the base class type and some rely upon the derived class
type.</p>
<p>I suppose another solution would be to do something like
this:</p>
<pre>
<code>_injector.map(SGDialogEngine).asSingleton();
_injector.map(DialogEngine).toProvider(new SimpleProvider(function() : * {
return _injector.getInstance(SGDialogEngine);
}));</code>
</pre></div>mike.canntag:robotlegs.tenderapp.com,2009-10-18:Comment/382125412015-10-19T14:02:55Z2015-10-19T14:02:55ZMapping multiple types to same singleton<div><p>Thank you for your appreciation, Mike!! Yeah, I'm trying to keep
this forum alive, but now, without the combined brainpower of the
great rl creator, contributors and users, the forum is not the same
as it was years ago, of course.</p>
<p>+1 to your solution</p>
<p>If you think this is resolved, you can mark the discussion as
such, or let me know if/when I can close it.<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/382125412015-10-19T23:47:37Z2015-10-19T23:47:40ZMapping multiple types to same singleton<div><p>Sure, im not sure how to mark it as resolved but I think it
is..</p></div>mike.canntag:robotlegs.tenderapp.com,2009-10-18:Comment/382125412015-10-20T17:04:54Z2015-10-20T17:04:54ZMapping multiple types to same singleton<div><p>That's the "Close the discussion" link-button on the right of
the screen. When a discussion gets closed, it appears as 'resolved'
in the list of discussions</p>
<p>Closing it now...</p>
<p>See you on the other thread :)</p></div>Ondina D.F.