What is Dependency Injection?
Cameron McKenzie
@cameronmcnzAbout
Welcome to The Cameron McKenzie Developer's Channel – your all-in-one hub for mastering Java, Spring Boot, and Git! Whether you're a beginner or an advanced developer, our channel is packed with detailed tutorials, expert tips, and practical advice on building modern, scalable applications using the powerful Spring Boot framework. We cover everything you need to know about Spring Boot, from the fundamentals to advanced concepts, with in-depth tutorials on the most important Spring Boot starters: Spring Boot Starter Web Spring Boot Starter Security Spring Boot Starter Data JPA Spring Boot Starter Actuator Spring Boot Starter OAuth2 In addition to Spring Boot, we place a strong emphasis on Git, the version control system every developer should know. We cover key Git concepts and commands to help you collaborate effectively and manage your codebase. Want to learn Spring, Java, Git and even Python and Mojo? You're in the right place!
Latest Posts
Video Description
What is dependency injection? What is Inversion of Control? There are two of the most misunderstood topics in all of software development, and the amount of misinformation on the Internet isn't helping. In this Dependency Injection tutorial we will explain exactly what Dependency Injection is, what Dependency Injection isn't, and what types of things you can do with modern Dependency Injection and Inversion of Control frameworks. Now what follows below is AI generated content to capture keywords, and it may very well be wrong. So watch the video and head over to TheServerSide where I'm the Editor-in-Chief. We've got lots of great and accurate information on IoC and DI. *** Ignore what's below *** Inversion of Control (IoC) and Dependency Injection (DI) are key concepts in modern software development, especially in object-oriented programming (OOP). These patterns help developers create loosely coupled, more maintainable, and testable code. Here’s a look at their history and evolution. Origins of Inversion of Control (IoC) The concept of Inversion of Control predates Dependency Injection and has roots in OOP's early principles. In the 1980s, as OOP started gaining traction with languages like Smalltalk, C++, and later Java, developers began exploring how to make code more reusable and adaptable. The traditional approach to software design was procedural, where control flow was tightly managed by the code itself, making it hard to modify or extend without altering core functionality. IoC emerged as a solution to this rigidity. Rather than a module controlling its dependencies directly, the control flow was "inverted"—externalizing responsibilities such as creating objects or invoking specific actions. This concept was further popularized through the work of software design pioneers who aimed to make software architecture more modular and dynamic. One early example of IoC was the “Hollywood Principle”: “Don’t call us, we’ll call you.” This phrase captures the essence of IoC: instead of objects making decisions on when to call each other, the control flow is managed by a framework or an external component. The Hollywood Principle was instrumental in the development of graphical user interface (GUI) libraries, event-driven programming, and frameworks. Rise of IoC Frameworks In the 1990s, IoC started to gain prominence through early frameworks like Microsoft’s Component Object Model (COM) and JavaBeans. These technologies introduced basic forms of IoC by encouraging components to be managed externally rather than through direct calls. However, IoC remained somewhat informal and didn’t have a standardized approach or terminology. With the rise of enterprise Java applications in the late 1990s and early 2000s, the need for more sophisticated management of object dependencies became apparent. The Java community was particularly active in exploring ways to make large-scale applications easier to build and maintain, which led to the emergence of the Java EE (Enterprise Edition) platform. The complexity of these applications highlighted the need for patterns that could handle the creation and management of objects more flexibly. Dependency Injection Emerges Dependency Injection, a specific form of IoC, was formally introduced in the early 2000s. DI provides a way to supply a class’s dependencies from the outside rather than having the class create its dependencies. This approach separates the construction of objects from their use, enabling better separation of concerns and making the system more modular and easier to test. Martin Fowler, a prominent software engineer and author, popularized the term "Dependency Injection" in his 2004 article titled "Inversion of Control Containers and the Dependency Injection pattern." Fowler’s article clarified the DI pattern and articulated its benefits, such as improved testability, decoupling, and maintainability. He categorized DI into three types: Constructor Injection: Dependencies are provided through a class constructor. Setter Injection: Dependencies are set through public setter methods. Interface Injection: The dependency provides an injector method that injects the dependency into the client, a less common approach. Around the same time, Java developers were experimenting with lightweight containers like Spring Framework and Google Guice, which quickly adopted and popularized DI. These frameworks provided powerful tools to manage dependencies, making it easier to configure and wire objects together without tightly coupling them. Spring, in particular, became one of the most widely used frameworks for DI, offering extensive support for configuring dependencies through XML, annotations, and Java-based configuration.
Upgrade Your Everyday
AI-recommended products based on this video

Amazon Echo Show 8 (newest model), With Spatial Audio, Smart Home Hub, and Alexa, Charcoal

Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, with Active Noise Cancellation, Adaptive Audio, Transparency Mode, Personalized Spatial Audio, USB-C Charging Case, Wireless Charging, H2 Chip

Wireless Earbuds, Bluetooth 5.4 Headphones, True Wireless Stereo Earphones with IPX7 Waterproof, Noise Cancelling Mic, Fast Charging and Comfort Fit Ear Buds for Sports/Workouts - Black

Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, Personalized Spatial Audio, Sweat and Water Resistant, USB-C Charging Case, H2 Chip, Up to 30 Hours of Battery Life, Effortless Setup for iPhone

Apple AirPods Pro 2 Wireless Earbuds, Active Noise Cancellation, Hearing Aid Feature, Bluetooth Headphones, Transparency, Personalized Spatial Audio, High-Fidelity Sound, H2 Chip, USB-C Charging

Smart Watch for Men/Women, 1.95" AMOLED Fitness Tracker Watches with Bluetooth Calls/Flashlight/100+ Sport Modes Heart Rate/Sleep Monitor Ultra Lightweight Ultrathin Design

Smart Watch for Men Women (Answer/Make Call), 1.96" HD Smartwatch Fitness Activity Tracker, 110+ Sports IP68 Waterproof, Heart Rate/Sleep Monitor/Pedometer/Calories, Fitness Watch for Android iOS
![Apple Watch Series 10 [GPS 46mm case] Smartwatch with Rose Gold Aluminium Case with Light Blush Sport Band - M/L. Fitness Tracker, ECG App, Always-On Retina Display, Water Resistant](https://m.media-amazon.com/images/I/61nNNMI1cFL._AC_UL960_FMwebp_QL65_.jpg)
Apple Watch Series 10 [GPS 46mm case] Smartwatch with Rose Gold Aluminium Case with Light Blush Sport Band - M/L. Fitness Tracker, ECG App, Always-On Retina Display, Water Resistant
![Apple Watch Series 10 [GPS 42mm case] Smartwatch with Jet Black Aluminium Case with Black Sport Band - S/M. Fitness Tracker, ECG App, Always-On Retina Display, Water Resistant](https://m.media-amazon.com/images/I/6105jZyXyPL._AC_UL960_FMwebp_QL65_.jpg)
Apple Watch Series 10 [GPS 42mm case] Smartwatch with Jet Black Aluminium Case with Black Sport Band - S/M. Fitness Tracker, ECG App, Always-On Retina Display, Water Resistant

NOCO Boost GB40: 1000A UltraSafe Jump Starter – 12V Lithium Battery Booster Pack, Portable Jump Box, Power Bank & Jumper Cables - for 6.0L Gas and 3.0L Diesel Engines

UGREEN Nexode Power Bank 20000mAh 130W Portable Charger 72Wh PD Fast Charging 3-Port USB C Battery Pack with TFT Smart Display for MacBook/iPad/iPhone 16/Samsung S24 and More

ANKER 737 Power Bank, 24,000mAh 3-Port Laptop Portable Charger with 140W Fast Charging, Smart Display, for Outdoor Work, Compatible with iPhone 16/15/14 Series, Vision Pro, Samsung, MacBook, and More

VOLTME Portable Charger, Slim 10000mAh 5V/3A Power Bank, USB C in&Out High-Speed Charging Battery Pack, Travel Essentials Dual Output Compatible with iPhone 16 15 14 13 12 Samsung Google iPad etc

Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, with Active Noise Cancellation, Adaptive Audio, Transparency Mode, Personalized Spatial Audio, USB-C Charging Case, Wireless Charging, H2 Chip

Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, Personalized Spatial Audio, Sweat and Water Resistant, USB-C Charging Case, H2 Chip, Up to 30 Hours of Battery Life, Effortless Setup for iPhone

Apple AirPods Pro 2 Wireless Earbuds, Active Noise Cancellation, Hearing Aid Feature, Bluetooth Headphones, Transparency, Personalized Spatial Audio, High-Fidelity Sound, H2 Chip, USB-C Charging

Bose QuietComfort Bluetooth Headphones, Wireless Headphones with Active Over Ear Noise Cancelling and Mic, Deep Bass, Up to 24 Hours of Playtime, White Smoke

Barnyard Designs Indoor Herb Garden Planter Set with Tray, Metal Windowsill Plant Pots with Drainage for Outdoor or Indoor Plants, Set/3 (Black)

Eye Contact Web Camera for Desktop Computer – 1080P USB Camera with Microphone & Stand, Center Cam for Laptop or Desktop, Manual Focus, Plug & Play for macOS & Windows(Black)
![PEHAEL 3+3Pack for iPhone 17 Pro Max Privacy Screen Protector with Camera Lens Protector Full Coverage Anti-Spy Tempered Glass Film 9H Hardness Easy Installation Bubble Free [6.9 inch]](https://m.media-amazon.com/images/I/61PnVkv6KKL._AC_UL960_FMwebp_QL65_.jpg)
PEHAEL 3+3Pack for iPhone 17 Pro Max Privacy Screen Protector with Camera Lens Protector Full Coverage Anti-Spy Tempered Glass Film 9H Hardness Easy Installation Bubble Free [6.9 inch]
![Ailun 3 Pack Screen Protector for iPhone 16 Pro Max [6.9 inch] + 3 Pack Camera Lens Protector with Installation Frame,Sensor Protection,Dynamic Island Compatible,Case Friendly Tempered Glass Film](https://m.media-amazon.com/images/I/815keamN-BL._AC_UL960_FMwebp_QL65_.jpg)
Ailun 3 Pack Screen Protector for iPhone 16 Pro Max [6.9 inch] + 3 Pack Camera Lens Protector with Installation Frame,Sensor Protection,Dynamic Island Compatible,Case Friendly Tempered Glass Film


















