Samuel
Samuel

Reputation: 12341

NInject ConstructorArgument with lambda expression

Is there any way to create an instance of ConstructorArgument using lambda expression instead of hardcoded string to define the name of the property?

Something like this:

var validator = Ioc.Kernel.Get<Validators.Security.UserGroupValidator>(new ConstructorArgument( x => x.ValidationDictionary, new ValidationDictionary())

In my case, the ValidationDictionary is not the same in many places and for this reason, I can't use a Provider.

Upvotes: 0

Views: 824

Answers (1)

Daniel Marbach
Daniel Marbach

Reputation: 2314

You can use the ToConstructor binding like

http://www.planetgeek.ch/2011/05/28/ninject-constructor-selection-preview/

   Bind<UsergroupValidator>().ToConstructor(_ => new Usergroupvalidator(new ValidationDictionary());

Or even let the validation dictionary be injected as defined in the blogpost.

Upvotes: 2

Related Questions