簡單的 IoC 容器:BarbarianIOC

jopen 11年前發布 | 58K 次閱讀 面向方面AOP/IoC BarbarianIOC

BarbarianIOC 是一個簡單的 .NET 實現的 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();</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1361839694927

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!