IoC is a well-known pattern that invents the control of how dependent objects are created within software components. Using DI allows us to implement IoC in our software applications. Let's take a look at an actual scenario to illustrate what this means.
If you are already familiar with DI and IoC, feel free to skip this section and jump right into the code in the next section. If you're not familiar with this topic, or have not had a chance to use it in your real-life projects, this section aims to help you become more comfortable with it.
Both experienced developers and beginners have opinions on whether DI is right for them or not. As a result, there are arguably many pros and cons for and against the use of DI and IoC in your projects.
Here are some reasons why DI is a good choice:
Helps with adhering to the Dependency Inversion Principle (DIP)
Allows objects to be easily swapped with replacements
Facilitates the use of the Strategy Design Pattern (SDP...