I\'m evaluating ninject2 but can\'t seem to figure out how to do lazy loading other than through the kernel.
From what I can see that kind of defeats the purpose of
There is a simpler way to do this:
public class Module : NinjectModule
{
public override void Load()
{
Bind(typeof(Lazy<>)).ToMethod(ctx =>
GetType()
.GetMethod("GetLazyProvider", BindingFlags.Instance | BindingFlags.NonPublic)
.MakeGenericMethod(ctx.GenericArguments[0])
.Invoke(this, new object[] { ctx.Kernel }));
}
protected Lazy GetLazyProvider(IKernel kernel)
{
return new Lazy(() => kernel.Get());
}
}