当前位置:网站首页>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
边栏推荐
- Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
- 高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
- [binary tree] binary tree path finding
- 淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口
- Getting started with DES encryption
- DOM node object + time node comprehensive case
- As we media, what websites are there to download video clips for free?
- JVM(二十) -- 性能监控与调优(一) -- 概述
- 1.AVL树:左右旋-bite
- 论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
猜你喜欢
架构设计的五个核心要素
JVM (19) -- bytecode and class loading (4) -- talk about class loader again
Jhok-zbl1 leakage relay
How Alibaba cloud's DPCA architecture works | popular science diagram
Initial experience of annotation
Jhok-zbg2 leakage relay
4. Object mapping Mapster
Flink SQL realizes reading and writing redis and dynamically generates hset key
Mapbox Chinese map address
1. AVL tree: left-right rotation -bite
随机推荐
Paper reading [semantic tag enlarged xlnv model for video captioning]
JSP setting header information export to excel
Leakage relay llj-100fs
[binary tree] binary tree path finding
【js组件】自定义select
一条 update 语句的生命经历
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
4. Object mapping Mapster
Getting started with DES encryption
数字化创新驱动指南
As we media, what websites are there to download video clips for free?
Educational Codeforces Round 22 B. The Golden Age
照片选择器CollectionView
5阶多项式轨迹
高压漏电继电器BLD-20
Torch optimizer small parsing
不同网段之间实现GDB远程调试功能
消息队列:消息积压如何处理?
论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
app clear data源码追踪