使用 Ninject 注入整数
我有以下课程
public class Foo
{
public Foo(int max=2000){...}
}
,我想使用 Ninject 向 Foo 中注入一个常量值。我已经尝试过此操作,
Bind<Foo>().ToSelft().WithConstructorArgument("max", 1000);
但当我尝试使用 _ninject.Get
时出现以下错误:
Error activating int
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency int into parameter max of constructor of type Foo
I have folowing class
public class Foo
{
public Foo(int max=2000){...}
}
and I want to use Ninject to inject a constant value into Foo. I have try this
Bind<Foo>().ToSelft().WithConstructorArgument("max", 1000);
but I get following error when I try to use _ninject.Get<Foo>
:
Error activating int
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency int into parameter max of constructor of type Foo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下对我有用:
the below works for me: