例如,如何使用 Ninject 将构造函数参数绑定到位图?
我目前有一个这种形式的类:
class Abc {
private readonly IDisposable disposable;
public Abc(IDisposable disposable) {
this.disposable = disposable;
}
...
}
现在,我想知道如何使用构造函数将 IDisposable
绑定到 Bitmap
Bitmap(int widht, int height)
。
我尝试过下面的代码,但它似乎没有做到这一点:
class TestModule : NinjectModule {
public override void Load()
{
Bind<IDisposable>().To<Bitmap>()
.WithConstructorArgument("width", 10)
.WithConstructorArgument("height", 22)
;
}
}
I currently have a class of this form:
class Abc {
private readonly IDisposable disposable;
public Abc(IDisposable disposable) {
this.disposable = disposable;
}
...
}
Now, I'd like to know how can I make a binding of IDisposable
to Bitmap
using the
Bitmap(int widht, int height)
constructor.
I've tried with the following piece of code, but it doesn't seem to do it:
class TestModule : NinjectModule {
public override void Load()
{
Bind<IDisposable>().To<Bitmap>()
.WithConstructorArgument("width", 10)
.WithConstructorArgument("height", 22)
;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,这很简单:
例如,会起作用。不过,还有其他几种方法可以做到这一点。它们都在 Bind() 返回对象中。
Doh, this was an easy one:
will work, for example. There are a couple of other ways of doing it, though. They are all in the Bind() return object.