Ninject Lazy Load
namespace LayzyLoadTest { [TestClass] public class UnitTest1 { private IKernel InitKernel() { Ninject.IKernel kernel = new Ninject.StandardKernel(new LazyBinding()); //kernel.Load<LazyBinding>(); kernel.Bind<IPerson>().To<Father>(); kernel.Bind<IVehicle>().To<Car>(); kernel.Bind<IPlace>().To<Road>().Named("comm"); kernel.Bind<IPlace>().To<LazyRoad>().Named("lazy"); return kernel; } [TestMethod] public void TestMethod1() { var comm = InitKernel().Get<IPlace>("comm"); comm.CurSpeed(); comm.ShowSpeed(); //Console.WriteLine("------------------------------------------------"); //var lazy = kernel.Get<IPlace>("lazy"); ////lazy.CurSpeed(); ////lazy.ShowSpeed(); }
[TestMethod] public void Lazy() { var lazy = InitKernel().Get<IPlace>("lazy"); lazy.CurSpeed(); Console.WriteLine("----over curspeed--------------------"); lazy.ShowSpeed(); } } }