7

I am looking for a way to do something like this with Ninject :

// Sample from the Unity application block
IMyService result = myContainer.Resolve<IMyService>("Data"); 

( from http://msdn.microsoft.com/en-us/library/cc440957.aspx )

Is it possible?

sandesh247
  • 1,658
  • 1
  • 18
  • 24

2 Answers2

18

Ninject 2.0 has this capability:

Bind<IMyService>().To<MyServiceA>().Named("Data");
Bind<IMyService>().To<MyServiceB>().Named("SomethingElse");

kernel.Get<IMyService>("Data"); // will return MyServiceA
Nate Kohari
  • 2,216
  • 17
  • 13
0

AFAIK there is no way to do that directly in Ninject, but you can use Contextual Binding instead.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275