开发者

How, for example, to make a binding with constructor arguments to a Bitmap with Ninject?

开发者 https://www.devze.com 2023-01-12 04:43 出处:网络
I currently have a class of this form: class Abc { private readonly IDisposable disposable; public Abc(IDisposable disposable) {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消