当前位置:网站首页>What is dependency injection (DI)
What is dependency injection (DI)
2022-07-07 05:35:00 【PIKapikaaaa】
DI The full name is Dependency Injection, It's called dependency injection in Chinese .
It is related to the reversal of control (IoC) It means the same thing , It's just that these two terms describe the same concept from two perspectives . For one Spring For beginners , These two terms are difficult to understand , Now we will describe these two concepts in simple language .
When a Java object ( caller ) You need to call another Java object ( Callees , That is, the dependent object ) when , In the traditional mode , Callers usually use “new Callees ” Code to create objects , Pictured 1 Shown . This approach will lead to increased coupling between the caller and the callee , It is not conducive to the upgrading and maintenance of later projects .

chart 1 The caller creates the callee object
In the use of Spring After the framework , An instance of an object is no longer created by the caller , But by the Spring Container to create ,Spring The container is responsible for controlling the relationship between programs , Instead of being directly controlled by the caller's program code . such , Control has shifted from application code to Spring Containers , There is a reversal of control , This is it. Spring The reversal of control .
from Spring From the perspective of containers ,Spring The container is responsible for assigning the dependent object to the caller's member variable , This is equivalent to injecting the caller with the instance it depends on , This is it. Spring Dependency injection of , Pictured 2 Shown .

chart 2 Inject the callee object into the caller object
边栏推荐
- JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
- JVM(二十) -- 性能监控与调优(一) -- 概述
- [Oracle] simple date and time formatting and sorting problem
- LabVIEW is opening a new reference, indicating that the memory is full
- 常用消息队列有哪些?
- 淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口
- 利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点
- 基于NCF的多模块协同实例
- 分布式事务解决方案之TCC
- Record a pressure measurement experience summary
猜你喜欢

English grammar_ Noun possessive

张平安:加快云上数字创新,共建产业智慧生态

Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface

消息队列:如何确保消息不会丢失

Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format

Use Zhiyun reader to translate statistical genetics books

Unity让摄像机一直跟随在玩家后上方

Unity keeps the camera behind and above the player

How digitalization affects workflow automation

集群、分布式、微服务的区别和介绍
随机推荐
纪念下,我从CSDN搬家到博客园啦!
English语法_名词 - 所有格
Addressable pre Download
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
Egr-20uscm ground fault relay
Tablayout modification of customized tab title does not take effect
基于NCF的多模块协同实例
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
漏电继电器JOLX-GS62零序孔径Φ100
ssm框架的简单案例
How can project managers counter attack with NPDP certificates? Look here
Leetcode: maximum number of "balloons"
App clear data source code tracking
什么是消息队列?
CentOS 7.9 installing Oracle 21C Adventures
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
Leakage relay jelr-250fg
[JS component] date display.
常用消息队列有哪些?