Ninject 与多个接口绑定
我有一个像这样的控制器:
public class Controller
{
public TokenService _service;
[Inject]
public Controller(TokenService service)
{
_service = service;
}
}
TokenService 看起来像这样:
public class TokenService: IInterface1, IInterface2 {}
如何在 Ninject 中绑定它?我本以为我需要将控制器中的 TokenService 构造函数参数更改为这两个接口之一。
我有2个接口的原因是因为TokenService用于DotNetOpenAuth。
I have a controller like this:
public class Controller
{
public TokenService _service;
[Inject]
public Controller(TokenService service)
{
_service = service;
}
}
With TokenService looking like this:
public class TokenService: IInterface1, IInterface2 {}
How do I bind this in Ninject? I would have thought I needed to change the TokenService constructor parameter in the Controller to be one of those 2 interfaces.
The reason I have 2 interfaces is because TokenService is used for DotNetOpenAuth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您根本不需要绑定它,因为据我所知,Ninject 会自动将所有具体类型绑定到自身。
如果不是这种情况,请自行执行:
Normally, you don't need to bind it at all, because as far as I know, Ninject automatically binds all concrete types to themselves.
If this is not the case, just do it yourself: