Member-only story
The Difference Between Dependency Inversion and Dependency Injection
Introduction
Understanding Dependency Inversion has been a long journey for me. I quickly understood Dependency Injection as it gained popularity and, as somebody who likes automated unit tests, could immediately see benefits of using it for testing. What is Dependency Inversion though and how does it differ from Dependency Injection? In this article we will look at a very simple example of Dependency Injection and develop it further to consider Dependency Inversion.
Different Types of Dependency
To understand Dependency Inversion you need to understand two different types of dependency:
- Flow of Control Dependency — when you are debugging code and the line of execution goes from one project into another project or dll.
- Source Code Dependency — where one project references another project or dll.
What do we mean by Dependency Inversion
Dependency Inversion is where the Flow of Control Dependency goes in one direction between two projects or dlls, but the Source Code Dependency goes in the other direction.