What’s is Dependency Injection (DI) ? How Can I Use Swinject Framework to Help Me On This?

Felipe F Garcia
The Dev Project
Published in
14 min readMar 3, 2019

--

Here we will talk about the concept behind this pattern, look into some situations where this occurs, and how we can change this in order to have a more decoupled code using Dependency Inject pattern. The next step will be how we can use Swinject framework in order to help us apply this pattern and the advantages that he brings to us.

For those that perhaps would like a video that shows more in general, I did a talk about, can be an introduction: https://youtu.be/8a_oL8-ioqA

What’s Dependency Injection or Dependency Inversion Principle?

By the book is: The Dependency Inversion Principle Wikipedia entry defines:

“In object-oriented programming, the Dependency Inversion Principle refers to a specific form of decoupling software modules. When following this principle, the conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are reversed, thus rendering high-level modules independent of the low-level module implementation details.”

But in a more simple way, Dependency Injection is a pattern that allows an Object to be injected in a way that is completely independent of any object consumption. This improves when any change that needs to be made on one side will not impact another side's implementation.

--

--

Felipe F Garcia
The Dev Project

Backend Engineer 💻 Java 👾 Python 🐍 Top Writer in Medium at the topic Technology 🚀 With a mindset to help and share knowledge 📖.