简体   繁体   English

谁能告诉我 spring 中的控制反转 (IOC) 和依赖注入 (DI) 有什么区别?

[英]can anyone please tell me what is the difference between Inversion of Control (IOC) and Dependency Injection (DI) in spring?

I'am seriously figuring out this for the last one week and continuously keep on reading articles and blogs so that I can understand the difference in the very leman language and terms so that I can understand easily!!!!!在过去的一周里,我认真地弄清楚了这一点,并不断地阅读文章和博客,以便我能够理解非常简单的语言和术语的差异,以便我能够轻松理解!!!!!!

Dependency injection is simply about depending on an abstract interface and passing a concrete implementation of that interface to your class through the constructor or a setter method.依赖注入只是依赖于一个抽象接口,并通过构造函数或 setter 方法将该接口的具体实现传递给您的 class。 This allows you to use a different concrete implementation without changing your class. This is useful, for instance for testing.这允许您在不更改 class 的情况下使用不同的具体实现。这很有用,例如用于测试。

IoC is also known as the Hollywood principle: don't call us, we call you. IoC也被称为好莱坞原则:不要打电话给我们,我们打电话给你。 In this case a framework defines an interface and the application provides the concrete implementation.在这种情况下,框架定义接口,应用程序提供具体实现。 This helps to limit dependencies between classes.这有助于限制类之间的依赖关系。 IoC is often implemented using dependency injection, but it's not a hard requirement. IoC 通常使用依赖注入来实现,但这并不是硬性要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 框架中的依赖注入和控制反转是什么? - What is Dependency Injection and Inversion of Control in Spring Framework? Spring框架中的控制反转和依赖注入是什么意思? 和有什么区别? 为什么在Spring框架中? - What does mean Inversion of Control and Dependency Injection in Spring Framework? and what is difference ? Why in the Spring framework? CDI(上下文和依赖注入)和DI(依赖注入)之间有什么区别 - What is the difference between CDI (Contexts and Dependency Injection) and DI (Dependency Injection) 什么是简单英语中的AOP,依赖注入和控制反转 - What is AOP, Dependency Injection and Inversion Of Control in Simple English Spring 中的自动装配与依赖注入有什么区别? - What is difference between autowiring vs dependency injection in Spring? Spring IoC-依赖注入-> NullPointerException - Spring IoC - Dependency Injection -> NullPointerException Spring 3带有注释的依赖注入(IoC) - spring 3 Dependency injection( IoC) with annotation 如果没有依赖注入也可以完成,那么 Java Spring 中的 XML IoC 有什么意义? - What is the point of XML IoC in Java Spring if dependency injection can be done without it? 这两次春季IOC注射有什么区别? - What is difference between these 2 Spring IOC injections? Spring Web依赖注入(IOC)和ServletContextListener - Spring web Dependency Injection(IOC) and the ServletContextListener
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM