Introducing IoC and DI in Spring

Peter Späth, Iuliana Cosmina, Rob Harrop, Chris Schaefer · Apress eBooks · 2023

Chapters and have introduced you to the Spring world, explaining why this framework is necessary and why dependency injection is so cool and useful. In essence, Spring was built to make dependency injection easy. This software design pattern implies that dependent components delegate the dependency resolution to an external service that will take care of injecting the dependencies. The dependent component is not allowed to call the injector service and has very little to say when it comes to the dependencies that will be injected. This is why the behavior is also known as the “Don’t call us, we’ll call you!” principle, and it is technically known as inversion of control (IoC). If you do a quick Google search, you will find a lot of conflicting opinions about dependency injection and inversion of control. You will find programming articles calling them programming techniques, programming principles, and design patterns. However, the best explanation comes from an article by Martin Fowler, which is recognized in the Java world as the highest authority when it comes to design patterns. If you do not have the time to read it, here is a summary: Inversion of control is a common characteristic of frameworks that facilitate injection of dependencies. And the basic idea of the dependency injection pattern is to have a separate object that injects dependencies with the required behavior, based on an interface contract.

Read the paper · More papers on PaperTik