星期三, 11月 23, 2005

[資訊雜記]Inversion of Control

本想看看 .Net 實做 Spring專案的.找著找著,又看到了 Castle. 後來發現他們都用了所謂的 Inversion of Control 的概念.

這我就好奇了,甚麼是 Inversion of Control ??

這裡看到一段很好的解說:
"That's the basic concept of Inversion of Control; you don't create your objects, you describe how they should be created. You don't directly connect your components and services together in code, you describe which services are needed by which components, and the container is responsible for hooking it all together. The container creates all the objects, wires them together by setting the necessary properties, and determines when methods are invoked."


然後提到大致上有三種實做的方式:
type-3 Services dependencies are provided as constructor parameters (and are not exposed as JavaBeans properties). This is the exclusive approach used by PicoContainer, and is also used in HiveMind and Spring.


接著又提到 Inversion of Control Container 應該被稱為 Dependency Injection pattern 會比較恰當...看這篇:Inversion of Control Containers and the Dependency Injection pattern
PicoContainerCastle 很接近,應該都屬於 type-3 - constructor injection, 此外也有很重的 Interface Injection 味道.
上面那篇文章寫的很好,可以算是經典文了.

其他參考性的東西,不再贅述...
*Castle 官網上對 IoC 的說明就直接貼出兩篇經典文的網址.
*c# 對 IoC 的實做,目前有三個實做: StructureMap, Castle, Spring.net
*Open Source Inversion of Control Containers in C#
*Design Better Software with the Inversion of Control Pattern
*Inversion of Control
*PicoContainer - Inversion of Control
*Apache Excalibur - guide-patterns-ioc

沒有留言: