Delegate a Ninject Delegate to WithConstructorArgument

I need to specify a method in Ninject bindings as part of the constructor argument. The constructor for the class is as follows:

MyObject(Func<Populator> param1, TimeSpan time)

I searched and could not find a way to associate a delegate for Func. Is it possible? Ninject did not allow me to do this because it was expecting an object as an argument and did not accept a delegate.

Bind<IInterface>()
      .To<MyObject>()
      .InSingletonScope()
      .WithConstructorArgument
            ("param1", ctx => ctx.Kernel.Get<OtherWiredObject>().PopMethod)
      .WithConstructorArgument
            ("time", new TimeSpan(0,30,0));

Is there a way to make this behavior work in Ninject?

+5
source share
1 answer

You can define the binding as follows:

Bind<Func<Populator>>().ToMethod(ctx => ctx.Kernel.Get<OtherWiredObject>().PopMethod);
+3
source

All Articles