Di dependency injection + IOC control inversion (I) Definition

Source: Internet
Author: User

Dependency injection and control Inversion
Dependency injection and control inversion are common issues. This problem is also frequently encountered during interviews. There are a lot of materials on the Internet and a lot of information is found.
Let's talk about these definitions below.


Di dependency Injection
Dependency injection is both dependent and injected. It depends on containers and injects containers. It puts your objects into the container and depends on the container.

IOC control Inversion
Control inversion means that the creation of an object is determined by the container.
When we get started with programming, we generally use new to create objects. What are the disadvantages of this approach? This improves the Coupling Degree and inconsistency during object creation. What if we reduce coupling and create objects in a unified manner?
Can I create an object through the factory method? The factory can indeed achieve our goal. In the factory model, we have begun to contact the 'failed' in the control reversal. Because objects are not created by us, they are created by factories. When it comes to inversion, when we write code, the call between methods is always 'reversely '. All encapsulation uses reverse. Here is a clear description.
It is hard to understand the first reversal. To put it bluntly, the logic and objects you originally controlled are changed to third-party control. If you have created a public method that provides RSA encryption and decryption. When calling encryption, we only need to provide a key and plaintext to return a ciphertext, without knowing the implementation logic. This is inversion, not our control.
Let's talk about the history of control reversal.
As the number of objects increases, the factory mode seems cumbersome, because each object needs to be created by writing a method or even a class.
At this time, the idea of containers emerged. Use a container to load all objects. You only need to retrieve this object from the container. You do not need to manage objects.

 

 

 

You can follow your public account and share Original Articles with you with many years of experience.

   

Di dependency injection + IOC control inversion (I) Definition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.