2

I have these 3 interfaces:

interface IA {}
interface IB {}
interface IC {}

Also, I've this other interface which inherits from IA, IB and IC:

interface II : IA, IB, IC {}

Then, I've also created a class CC inherits from II:

class CC : II {}

I've created these bindings:

this.Bind<IA>().To<CC>().InSingletonScope();
this.Bind<IB>().To<CC>().InSingletonScope();
this.Bind<IC>().To<CC>().InSingletonScope();
this.Bind<II>().To<CC>().InSingletonScope();

I don't know if, each time I've to request for a whichever interface, NInject kernel is going to give the same singleton instance of CC.

So, I mean:

IA ia = kernel.Get<IA>();
IB ib = kernel.Get<IB>();

ia is the same instance that ib?

How could I get this behavior?

Jordi
  • 20,868
  • 39
  • 149
  • 333
  • Possible duplicate of [Binding singleton to multiple services in Ninject](https://stackoverflow.com/questions/3147996/binding-singleton-to-multiple-services-in-ninject) – BatteryBackupUnit Oct 18 '17 at 05:24
  • the difference to [your question from almost exactly one year ago](https://stackoverflow.com/questions/40125455/ninject-bind-multiple-types-to-the-same-singleton-instance) is minute. – BatteryBackupUnit Oct 18 '17 at 05:29

1 Answers1

4

As far as I know, this should work :

this.Bind<IA, IB, IC, II>().To<CC>().InSingletonScope();

The overload of Bind takes up to four type parameters.

jbl
  • 15,179
  • 3
  • 34
  • 101