Dependency Injection - Introduction
Dependency Injection(DI) is a coding pattern in which a class receives dependencies rather than creating them itself. Some developers and technology mavericks also refer to this as a design pattern.
It's widely used and is often called DI. We will refer to the Dependency Injection system as DI in all our sections.
Here's why we absolutely need DI:
- DI is a software design pattern in which a class receives its dependencies rather than creating the object itself
- DI creates and delivers objects, which are required dynamically just-in-time
- We can consider the injectables as our application's reusable repository
- DI allows independent development of dependency modules for remote development teams.
Note
No Angular apps can be completely written without using DI.
Now, let's revisit the preceding code we wrote without DI and write it with Angular DI:
class products { constructor(private _warehouse: warehouse, private _category: category) { // use _warehouse and _category...