IOC and DI

Source: Internet
Author: User

1. IOC and DI
Ioc:inversion of Control This is a very big concept.
The call of the object which is traditionally manipulated directly by the program code is given to the container, which realizes the Assembly and management of the object component through the container. The so-called "inversion of Control" concept is the transfer of control over a Component object, from the program code itself to the external container.
Di:dependency Injection
An IOC approach to implementation.
2. IOC and DI contact


3. Di's understanding
DI: Dependency Injection.
Relies on calls between-----classes (objects).
Here are a few questions to consider:
Question: Why is dependency generated?
Layered design concepts (should be familiar with web development): Easy to develop and maintain.
Dao--------->daoimpl--------->servie
The Daoimpl implementation Dao,service layer can use Daoimpl to manipulate the entity, rather than directly implementing DAO to manipulate the entity.

Question: How do I generate Daoimpl objects in the service layer?
Scenario One: Direct new, disadvantages: memory consumption and life cycle is not easy to control;
Scenario Two: Provided by the container. Advantages: With the use of the follow-up, do not consider the life cycle of control.

Issue: How to provide objects by container:
Dependency Injection.

Implementation: Configuration in an XML file.

Add:

IOC and DI

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.