php - About dependency injection
PHP中文网
PHP中文网 2017-05-16 13:04:23
0
2
432

If the construction parameter is a variable when instantiating a class, and this variable points to an object of the instantiated class. So is dependency injection used? Is my understanding correct?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
PHPzhong

Excerpted from Spring Practice

In ordinary Java development, when programmers need to rely on methods of other classes in a certain class, they usually use new to depend on the class and then call the method of the class instance. The problem with this kind of development is that new class instances are not easy to manage uniformly. , spring proposed the idea of ​​dependency injection, that is, dependent classes are not instantiated by programmers, but the spring container helps us specify new instances and inject the instances into classes that require the object. Another term for dependency injection is "inversion of control". The popular understanding is: usually when we create a new instance, the control of this instance is our programmers, and inversion of control means that the work of the new instance is not done by our programmers. Instead, leave it to the spring container.

具体有以下几种方式
  ● Set注入
  ● 构造器注入
  ● 静态工厂的方法注入
  ● 实例工厂的方法注入
淡淡烟草味

That’s right. The first sentence in your question, 如果实例化一个类时构造参数是个变量,而这个变量指向一个已实例化的类的对象。means to inject dependencies through the constructor. In addition to the constructor method, there are also several methods mentioned by @Qiu Kangsingasong.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template