How, for example, to make a binding with constructor arguments to a Bitmap with Ninject?
I currently have a class of this form:
class Abc {
private readonly IDisposable disposable;
public Abc(IDisposable disposable) {
this.disposable = dispo开发者_JAVA技巧sable;
}
...
}
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)
;
}
}
Doh, this was an easy one:
Bind<IDisposable>().ToConstant(new Bitmap(10, 22));
will work, for example. There are a couple of other ways of doing it, though. They are all in the Bind() return object.
精彩评论