------------------------------------------------------------------------
Understanding Ioc/di
1. Control reversal--who controls who? Control what? Why is it called reversal (corresponding to positive direction)? What is reversed? Why do I need to reverse?
Who Controls who? --Ioc/di Container control application
Control what? --Ioc/di container controls the creation, instantiation of the object itself; Ioc/di dependencies between container-controlled objects
Why is it called inversion (corresponding to the forward)? --Because now the application cannot take the initiative to get the external resources, but rather passively wait for the Ioc/di container to inject it with the resources it needs, so called inversion.
What aspects are reversed? -1. Create object 2. The way the program gets the resources is reversed.
Why do I need to invert? -1. After the introduction of the Ioc/di container, the system is more loose, and the management is more orderly; 2. Really loose coupling between classes
2. Dependent-- What is dependency (understood by name, understood by verb)? who depends on who? Why do you need to rely on?
What is dependency (understood by name, understood by verb)? -Dependency (understood by name): dependency relationship; Dependence (as understood by the verb): dependent action
Who depends on who? --application relies on the Ioc/di container
Why do I need to rely? --because of the reversal, the resources that the application relies on are the ioc/di containers.
Depend on what? The application relies on the Ioc/di container and relies on the Ioc/di container to inject the required resources into it. (e.g., dependencies)
3. Inject: Who injects into what? Why inject?
Who is injected into whom? --Ioc/di container injected into the application
into what? --inject the external resources that the application needs, such as dependencies
Why inject? -because these external resources are required for the program to function properly
4. Is dependency injection and control inversion the same concept?
is not the same concept, in fact, they describe the same event two, but from a different point of view: control reversal is from the angle of the Ioc/di container; Dependency Injection is from the perspective of the application
Description of control reversal: The Ioc/di container, in turn, controls the application and controls the external resources needed for the application lock (for example, external resources)
Description of Dependency Injection: The application relies on the Ioc/di container and relies on it to inject the required external resources.
5. What are the participants?
Ioc/di containers, applications
What is 6.ioc/di? What can you do?
What is Ioc/di?
IoC: A program development idea that uses the Ioc/di container in turn to control the external resources required by the application.
DI: That is, the application relies on the Ioc/di container to inject the necessary external resources, such a program development idea.
What can I do? --Loosely coupled objects
What do you do? -Using the spring framework, there are ioc/di containers that have been implemented
Where do you use it? -If you need to use external resources in the program, you can consider using the Ioc/di container
7. What is external resources
For a class, the so-called external resources, refers to the inside of their own class can not be obtained or implemented, such as: In the class need to read a configuration file, then this configuration file is equivalent to this class of external resources. Another example: A class inside To call Class B, then for a class B is an external resource.
8. IOC container
The simple understanding is that the IOC container is the software that implements the IOC idea and provides object creation, object assembly, and object lifecycle management.
Understanding of the IOC:
A. The application does not need to be an active new object, but rather describes how the object should be created
B. The application does not need to actively assemble the dependencies between objects, but rather describes which services are needed, and the IOC container will help you assemble and passively accept the assembly
C. Active passive is a component design approach that enables service consumers to not rely directly on service providers, and is a design principle that reduces dependencies between classes and classes
9. Use of Ioc/di container development needs to change ideas
A. Applications do not actively create objects, but describe how they are created
B. The Assembly of the service is not directly in the application code, but it is the container's responsibility to describe which component requires which service. That is, all the components are passive, the component initialization and the exclusive is the container, and the application simply implements the functionality of the application after acquiring the corresponding component.
Deep understanding of Ioc/di