Applications without Dependency Injection
Without the Dependency Injection framework, the life of a developer would be very tough. Take a look at the following drawbacks of not using Dependency Injection:
Every time a constructor parameter needs to be passed, we will need to edit the constructor definition of the class in all instances
We will need to create constructors and inject each of the required dependency classes individually
Let's take a look at an application without Dependency Injection to understand the challenges and shortfalls:
class products { available; category; constructor() { this.available = new warehouse(); this.category = new category(); } }
Let's analyze the preceding code snippet to understand better:
- We created a
class
namedproducts
. - In the
constructor
method, we instantiated the dependent classes,warehouse
andcategory
. - Note that, if the
warehouse
orcategory
class constructor definition changes, we will need to update manually all the instances of the classes...