ToConstant while binding in Kernel

296 Views Asked by At

We have a code something like below.

var xyz = method(); //method() returns an interface say **Interface1**

kernel.Bind<**Interface1**>().ToConstant(xyz);

I saw on stackoverflow at the below link:

Usage of binding to constants and binding to types in scopes with Ninject

Can we use Kernel.Bind<**Interface1**>().To(typeof(xyz)).InSingletonScope() if we want the object creation not at the this point but when call is made.

1

There are 1 best solutions below

4
Steven On
Bind<Interface1>().ToMethod(context => method()).InSingletonScope();