Пример #1
0
        static void Main(string[] args)
        {
            //// 下面两个demo违背的原则是:“具体应该依赖于抽象”
            //// 依赖倒置
            //// A.高层次的模块不应该依赖于低层次的模块,他们都应该依赖于抽象
            //IUnderly1 underly = new Underly1();
            //underly.WriteLine();

            //// B.抽象不应该依赖于具体
            //IUnderly2 underly2 = new Underly2();
            //underly2.WriteLine();

            //#region 依赖注入基本实现:依赖注入是把耦合的问题抛到了外部,抛到了要使用Top类型的对象中,这个问题就很严重了,我们怎么解决呢?
            //// 构造函数注入
            //Top top = new Top(new Underly3());
            //top.Execution();

            //// 属性注入
            //Top2 top2 = new Top2();
            //top2.Underly = new Underly3();
            //top2.Execution();

            //// 接口注入
            //Top3 top3 = new Top3();
            //top3.SetQuote(new Underly3());
            //top3.Execution();
            //#endregion

            #region IoCTest
            IIoCKernel iocKernel = new IoCKernel();
            iocKernel.Bind <IAbstractOne>().To <AchieveOne>();
            iocKernel.Bind <IAbstractTwo>().To <AchieveTwo>();
            iocKernel.Bind <IAbstractOne_One>().To <AbstractOne_One>();
            iocKernel.Bind <IAbstractOne_Two>().To <AbstractOne_Two>();
            DITest diType = iocKernel.GetValue <DITest>();
            diType.Writer("IoCFrameWorkTest");
            #endregion

            Console.ReadKey();
        }
Пример #2
0
 public TestController(IDapper dapper, DITest di)
 {
     Dapper = dapper;
     DI     = di;
 }