Mapping multiple interfaces to same singleton instance

Ivo's Avatar


08 May, 2013 10:53 AM

Hi all,

I'm trying to use RL2 to make sure that multiple interfaces, when injected, map to the same singleton instance. Sometimes for data hiding purposes, sometimes for polymorphism purposes.

Let's say I have an IFruit interface and an IApple interface extending IFruit, and an Apple class implementing IApple. Most of the time I'm just interested in injecting IFruit, but sometimes I want to use IApple. In both cases I want the same instance injected.

I currently do it as follows:;
    var appleProvider:DependencyProvider =;;

Is this the way to go? It feels rather complex and I'm not even sure what happens exaclty. If anyone can shed some light on this, would be much appreciated.

  1. Support Staff 1 Posted by creynders on 16 May, 2013 08:09 AM

    creynders's Avatar

    Hi, I'm sorry, your post got dumped into the spam queue.

    If I remember correctly that's the only way to do it. Could be I'm wrong though, don't have to time right now to look into it. Someone'll get back to you on this!

  2. Support Staff 2 Posted by Shaun Smith on 24 May, 2013 06:44 PM

    Shaun Smith's Avatar

    I think that might be the only way. Maybe a feature request for Swiftsuspenders is in order?

  3. Support Staff 3 Posted by creynders on 24 May, 2013 08:48 PM

    creynders's Avatar

    Yeah, a convenience method would be nice.
    Of course were we to reintroduce the IInjector+wrapper, we could solve it ourselves.

  4. Support Staff 4 Posted by Ondina D.F. on 18 Jul, 2013 03:00 PM

    Ondina D.F.'s Avatar
  5. Ondina D.F. closed this discussion on 18 Jul, 2013 03:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac