Yatrix
Yatrix

Reputation: 13805

How do I bind, using a constructor that takes a parameter?

Using Ninject, how can I bind using a constructor that accepts a parameter.

I see how I can do this:

kernel.Bind(Of IWidget).To(Of Widget)

But, what if Widget has a constructor that takes a string? Is there a way to bind this way:

kernel.Bind(Of IWidget).To(Of Widget(myParam))

Upvotes: 0

Views: 179

Answers (1)

User 12345678
User 12345678

Reputation: 7804

I believe .WithConstructorArgument will suffice for your need:

Bind(Of IWidget).To(Of Widget)
                .WithConstructorArgument("constructorArgumentOne", ...)

Upvotes: 1

Related Questions