© Tayo Koleoso 2020
T. KoleosoBeginning Quarkus Frameworkhttps://doi.org/10.1007/978-1-4842-6032-6_2

2. Dependency Injection

Tayo Koleoso1 
(1)
Silver Spring, MD, USA
 

As the old saying goes, “Teach a man to fish, and dependency injection will keep fresh fish coming,”1 dependency injection is the lifeblood of any serious enterprise Java application.

Dependency injection (DI) is the mechanism by which java objects are made available at specific points in your code by the runtime. It’s an implementation of the inversion of control (IoC) design pattern that makes it so that application code can be loosely coupled. So instead of non-DI code:
MyDependency myDependency = new MyDependency();
//some business logic
myDependency.cleanUp();
myDependency = null;
you ...

Get Beginning Quarkus Framework: Build Cloud-Native Enterprise Java Applications and Microservices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.