Dependency injection: Difference between revisions

Content deleted Content added
Tighten up verbiage
Licriss (talk | contribs)
m Grammatical change for clarity of implicit info
Tags: Visual edit Mobile edit Mobile web edit
Line 7:
Dependency injection is often used to keep code in-line with the [[dependency inversion principle]].<ref>{{Cite web |last=Erez |first=Guy |date=2022-03-09 |title=Dependency Inversion vs. Dependency Injection |url=https://betterprogramming.pub/straightforward-simple-dependency-inversion-vs-dependency-injection-7d8c0d0ed28e |access-date=2022-12-06 |website=Medium |language=en}}</ref><ref>{{Cite web |last=Mathews |first=Sasha |date=2021-03-25 |title=You are Simply Injecting a Dependency, Thinking that You are Following the Dependency Inversion… |url=https://levelup.gitconnected.com/you-are-simply-injecting-a-dependency-thinking-that-you-are-following-the-dependency-inversion-32632954c208 |access-date=2022-12-06 |website=Medium |language=en}}</ref>
 
In [[Statically typed language|statically-typed languages]] theusing dependency injection means a client typicallyonly needs to declares the [[Interface (computing)|interfaces]] of the services it uses, rather than their concrete implementations, making it easier to change which services are actually used at runtime without recompiling.
 
Application frameworks often combine dependency injection with [[Inversion_of_control|Inversion of Control]]. Under inversion of control, the framework first constructs an application object (such as a controller), then passes [[control flow]] to it. With dependency injection, the framework also instantiates the dependencies declared by the application object (often in the constructor method's parameters), and passes the dependencies into the object.<ref>{{Cite web |title=Spring IoC Container |url=https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/beans.html |access-date=2023-05-23 |language=en}}</ref>