What is Dependency Injection (DI) in Spring?

What is Dependency Injection (DI) in Spring?

A) A design pattern used to implement IoC
B) A way to inject code into a database
C) A method to increase application speed
D) A tool to manage user interfaces

Answer:

A) A design pattern used to implement IoC

Explanation:

Dependency Injection (DI) is a design pattern used to implement Inversion of Control (IoC). In DI, objects are provided their dependencies at runtime rather than creating them themselves. This is done by injecting the dependencies into the objects through constructors, setters, or interfaces.

In the Spring Framework, DI allows for loose coupling between components, making the code more modular, easier to maintain, and more testable. By managing dependencies externally, Spring can easily configure and manage the objects’ lifecycle and their interdependencies.

Reference links:

https://www.javaguides.net/p/spring-tutorial-beginners-to-expert.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top