Quick Glimpse


There are various practices to get along with the best approach during software development. It’s always best to know about multiple paradigms to at least have an idea of the ease that comes with each approach. Good Problem solvers don’t stick to one rule or one programming language or one framework or one library but find a solution that suits them best for a particular problem. So, what if we have a lot of dependencies to manage?

Dependency injection can come in handy during this time.

Standard dependency injection comes with four roles

a) Service
It includes objects containing functionality or dependent functionality

b) Interfaces
Are parts to connect with services

c) Client
Any end object which behavior depends upon service it uses

d) Injector
It Injects any service required to the client

The Prime benefit of using dependency injection is decreased coupling between classes and their dependencies. I love dependency injection as it helps to reduce a lot of boilerplate code since all dependencies are handled by a singular component.

 

A Brief Outlook


Let’s say we have class C dependent on Class B and A. Dependency Injection will help to resolve Class A and B. This means I can depend on the end class C to focus on inputs and expected outputs.

I won’t detail this article as this article is intended to provide a quick overview only.

You might not require dependency in many cases, so make use when your project requires/has lots of dependencies to manage.
 

A SIDE NOTE

If you are looking for dependency injection in JavaScript I would highly recommend Box by Haluka Framework for Dependency Injection.

https://haluka.dev/

I will be contributing to this framework which is a remarkable initiative by Robin and wish other open source contributors to join him in this journey.

You can read the following article from the author to get more insights into the Box

https://medium.com/@hacktivistic/dependency-injection-made-easy-for-node-js-with-box-3b2f58f7ecf8