Dependency injection: Difference between revisions

Content deleted Content added
decap
SporkBot (talk | contribs)
m Repair or remove missing or deleted templates
Line 66:
Similarly, because dependency injection does not require any change in code behavior, it can be applied to legacy code as a [[Code refactoring|refactoring]]. This makes clients more independent and are easier to [[Unit testing|unit test]] in isolation, using [[Method stub|stubs]] or [[mock object]]s, that simulate other objects not under test.
 
This ease of testing is often the first benefit noticed when using dependency injection.<ref>{{cCiteCite web |url=https://visualstudiomagazine.com/articles/2014/07/01/larger-applications.aspx |title = How to Refactor for Dependency Injection, Part 3: Larger Applications }}</ref>
 
=== Disadvantages ===
Line 82:
* Interface injection, where the dependency's interface provides an injector method that will inject the dependency into any client passed to it.
 
In some frameworks, clients do not need to actively accept dependency injection at all. In [[Java (programming language)|Java]], for example, reflection can make private attributes public when testing and inject services directly.<ref>{{cCiteCite web |title=AccessibleObject (Java Platform SE 7) |url=http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/AccessibleObject.html |access-date=2015-07-18 |website=docs.oracle.com }}</ref>
 
=== Without dependency injection ===