当前位置:网站首页>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
边栏推荐
- JVM(二十) -- 性能监控与调优(一) -- 概述
- How can professional people find background music materials when doing we media video clips?
- Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
- Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format
- Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
- AOSP ~binder communication principle (I) - Overview
- 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
- How digitalization affects workflow automation
- 做自媒体,有哪些免费下载视频剪辑素材的网站?
- Flink SQL 实现读写redis,并动态生成Hset key
猜你喜欢
CentOS 7.9 installing Oracle 21C Adventures
DJ-ZBS2漏电继电器
Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
High voltage leakage relay bld-20
Phenomenon analysis when Autowired annotation is used for list
分布式事务解决方案之TCC
JVM(二十) -- 性能监控与调优(一) -- 概述
4. Object mapping Mapster
漏电继电器LLJ-100FS
随机推荐
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
Writing process of the first paper
不同网段之间实现GDB远程调试功能
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
Let f (x) = Σ x^n/n^2, prove that f (x) + F (1-x) + lnxln (1-x) = Σ 1/n^2
Photo selector collectionview
Leakage relay llj-100fs
张平安:加快云上数字创新,共建产业智慧生态
NPDP产品经理认证,到底是何方神圣?
1.AVL树:左右旋-bite
4. Object mapping Mapster
漏电继电器LLJ-100FS
JVM (XX) -- performance monitoring and tuning (I) -- Overview
np. random. Shuffle and np Use swapaxis or transfer with caution
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
5阶多项式轨迹
Paper reading [open book video captioning with retrieve copy generate network]
说一说MVCC多版本并发控制器?