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();



        }

image
 
 
        [TestMethod]
        public void Lazy()
        {


            var lazy = InitKernel().Get<IPlace>("lazy");

            lazy.CurSpeed();

            Console.WriteLine("----over curspeed--------------------");

            lazy.ShowSpeed();
        }
    }
}

 

image



posted @ 2013-07-05 14:15  张保维  阅读(342)  评论(0编辑  收藏  举报