Dependency injection: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
No edit summary
Line 1:
{{Short description|Software programming technique}}
[[File:DependencyInjectionServiceProvider.png|alt=A diagram of an archetypical dependency injection container for the .NET platform.|thumb|Dependency injection is often used alongside specialized frameworks, known as 'containers', to facilitate program composition.]]
In [[software engineering]], '''dependency injection''' is a [[Software designprogramming patterntechnique|design patterntechnique]] in which an [[Object (computer science)|object]] or [[Subroutine|function]] receives other objects or functions that it depends on. Dependency injection aims to [[separation of concerns|separate the concerns]] of constructing objects and using them, leading to [[Loose coupling|loosely]] [[Coupling (computer programming)|coupled]] programs.<ref>{{Cite web |last=Seemann |first=Mark |title=Dependency Injection is Loose Coupling |url=http://blog.ploeh.dk/2010/04/07/DependencyInjectionisLooseCoupling/ |access-date=2015-07-28 |website=blog.ploeh.dk}}</ref><ref name="MarkSeeman2011P4" /><ref>Niko Schwarz, Mircea Lungu, Oscar Nierstrasz, “Seuss: Decoupling responsibilities from static methods for fine-grained configurability”, Journal of Object Technology, Volume 11, no. 1 (April 2012), pp. 3:1-23</ref> The pattern ensures that an object or function which wants to use a given [[Service (systems architecture)|service]] should not have to know how to construct those services. Instead, the receiving '[[Client (computing)|client]]' (object or function) is provided with its dependencies by external code (an 'injector'), which it is not aware of.<ref name="HollywoodPrinciple.c2">{{Cite web |title=HollywoodPrinciple |url=http://c2.com/cgi/wiki?HollywoodPrinciple |access-date=2015-07-19 |website=c2.com}}</ref> Dependency injection helps by making implicit dependencies explicit and helps solve the following problems:<ref>{{cite web |title=The Dependency Injection design pattern - Problem, Solution, and Applicability |url=http://w3sdesign.com/?gr=u01&ugr=proble |access-date=2017-08-12 |website=w3sDesign.com}}</ref>
* How can a [[Class (computer programming)|class]] be independent from the creation of the objects it depends on?
* How can an application, and the objects it uses support different configurations?