http://en.wikipedia.org/wiki/Dependency_injection
Martin Fowler
identifies three ways in which an object can get a reference to an
external module, according to the pattern used to provide the
dependency:
依照提供依賴項時使用的模式,Martin Fowler定義了三種對象可以從得到一個外部模塊引用的方式:
- Type 1 or interface injection,
in which the exported module provides an interface that its users must
implement in order to get the dependencies at runtime (as introduced by
Borland Delphi and followed up by C++Builder and JBuilder[citation needed]).
- Type 2 or setter injection, in which the dependent module exposes a setter method which the framework uses to inject the dependency.
- Type 3 or constructor injection,
in which the dependencies are provided through the class constructor.
This is the main form used by PicoContainer, although it also supports
setter injection.
- 類型1 接口注入,外部模塊提供一個接口,使用者必須實現此接口以在運行期得到依賴項(Borland Delphi引入,并在C++ Builder和JBuilder中繼續運用)。
- 類型2 設置器注入,使用者暴露一個設置器方法,框架將使用此方法注入依賴項。
- 類型3 構造器注入,依賴項通過類構造函數提供。這是PicoContainer使用的主要方式(盡管它同時也支持設置器注入)。
The open source Yan Container[1] provides support for arbitrary types of injection[2] besides the common ones defined above.
除了前列的幾種普通形式外,開源項目Yan Container還對任意形式的注入提供了支持。
Existing frameworks
現有框架
Dependency injection frameworks exist for a number of platforms and languages including:
在一些平臺和語言中都有依賴注入框架,包括:
ActionScript
C++
ColdFusion
Delphi
Java
Java 2 Micro Edition
.NET
PHP4
PHP5
Perl
Python
Ruby
See also
參見
External links
外部鏈接
Retrieved from "http://en.wikipedia.org/wiki/Dependency_injection"
Categories: Software components | Software architecture
Hidden categories: Articles to be merged since June 2008 | Articles lacking in-text citations | All articles with unsourced statements | Articles with unsourced statements since July 2008