How To Use Ninject Named Bindings With DependencyResolver and PropertyInjection

∥☆過路亽.° 提交于 2019-11-30 09:59:01
ryber

You can create a named binding to work on Alpha:

Bind<IRepository>().To<AlphaRepository>().Named("Alpha");

then you can specify others like:

Bind<IRepository>().To<AnotherRepository>().Named("Beta");

When your example constructor is used you will get the AlphaRepository.

In order to use the name with a property give the property a name attribute just like you you did for the param:

[Inject, Named("Alpha")]
public IRepository Foo {get; set;}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!