Comparison
Dependency injectionvsInversion of control
Dependency injection
the class asks for what it needs in its constructor and never goes looking, so a test can hand it anything.
Supplying a component's collaborators from outside instead of letting it construct or locate them. It is not a framework — passing an argument is dependency injection — and the whole benefit is that the dependency becomes visible in the signature and replaceable at the call site. It is the mechanical half of dependency inversion, which is the design principle about which direction the abstraction points.
Full entry →Inversion of control
you stopped writing the loop and started writing the thing the framework calls, and you no longer decide when.
The general shift where a framework owns the flow of control and your code fills in the parts, rather than your code calling a library when it chooses. Dependency injection is one specific case of it — control over which object you get — but so are event handlers, template methods and lifecycle callbacks. Confusing the general idea with the specific technique is the most common wrong answer to the interview question about the difference.
Full entry →