1. BarbarianIOC簡單的 IoC 容器

        聯(lián)合創(chuàng)作 · 2023-09-30 07:09

        BarbarianIOC 是一個(gè)簡單的 .NET 實(shí)現(xiàn)的 IoC 容器,示例代碼:

        Container = new Container();
        int someMockAge = 23; // this could come from anywhere (App.Config / database etc etc)
        
        //Register ALL components
        container.RegisterComponents(
                //where you can use concrete type
                new Component().For<Foo>().WithInstanceMode(InstanceMode.Transient),
                //or you can use an interface and it's implementation
                new Component().For<IBaz>().ImplementedBy<Baz>().WithInstanceMode(InstanceMode.Transient),
                //and you can also declare singleton instance mode if you like
                new Component().For<SomeIBazDependantClass>().WithInstanceMode(InstanceMode.Singleton),
                //and even supply some non IOC provided constructor params by way of an anonymous object
                new Component().For<SomeFooDependantClass>()
                    .DependsOn(new 
                        { 
                            age=someMockAge
                        })
                    .WithInstanceMode(InstanceMode.Transient)
            );
                    
        //allow the container to wire stuff up (essentially create Expression.New for all 
        //components to allow Container to compile and create some quicker lookup delegates)
        container.WireUp();
        瀏覽 26
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
          
          

            1. 日本操逼片 | 熟女嗷嗷叫高潮合集91 | A级片免费观看 | 女人被男人猛c高潮呻吟喷水 | 婷婷丁香六月 |