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 named products.
- In the constructor method, we instantiated the dependent classes, warehouse and category.
- Note that...