Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninject : Resolving an object by type _and_ registration name/identifier

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?

like image 813
sandesh247 Avatar asked Feb 10 '09 17:02

sandesh247


1 Answers

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
like image 110
Nate Kohari Avatar answered Sep 20 '22 04:09

Nate Kohari