Ninject : Resolving an object by type _and_ regist

2020-03-18 17:26发布

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?

2条回答
Evening l夕情丶
2楼-- · 2020-03-18 17:40

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

查看更多
forever°为你锁心
3楼-- · 2020-03-18 17:47

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
查看更多
登录 后发表回答