You can eat whatever you like.--IOC container

Source: Internet
Author: User

A meat-eating child, the dependence on meat is very strong, for the sake of children's health, the mother decided to play a strong control ability. You can't let your child decide what to eat, but the mother decides what the child eats. Slowly, the child no longer has a strong reliance on the meat and slowly becomes healthy. The mother succeeded in gaining control and injecting the child's dependence on the vegetables between the children and the vegetables.

  IOC containers are like the seasoning boxes we use when cooking, the youyanjiangcu used in the cooking process, the seasoning boxes are ready for you, and the seasoning boxes are available to you when you need them.

In the process of running a program, when a object completes a function, it needs to invoke the B object, then saya->b(Arelies onB). A complex business logic in the code, there must be a lot of dependencies. a->b,b->c,c->d (ADependentb,band rely onC,cand rely onD)This complex dependency makes code maintenance and implementation difficult, so is there a possibilityA, b,c,d, each realizes their own business logic, regardless of this dependency, which is managed by the other party. IOCwell achieved this, ObjectAdependent on the objectB,when an objectAneed to use objectBthe time,IOCThe container will immediately create an objectBSend To ObjectA. IOCa container is an object manufacturing plant, what you need, it will be sent to you, you directly use it, and no longer have to care about how you use the things are made, do not care how the last is destroyed, it all byIOCcontainers are arranged.

In a traditional implementation, the internal code of the program controls the relationship between components. We often use the New keyword to implement a combination of relationships between two components, which can cause coupling between components. The IOC solves this problem well, and it will implement inter-component relationships by referring to external containers from within the program, meaning that a container dynamically injects a dependency between components into the component at run time.

definition: Span lang= "en-US" style= "Font-family:calibri" > IOC ( inversion of Control ) The basic idea of the implementation of control inversion is DI Dependency Injection ( Dependency injection ) : Dependency Injection (DI) and inversion of control (IOC) are the same thing that is described from different angles, that is, by introducing an IOC container, the decoupling of objects is realized by means of dependency injection.

through the computer USB The interface reads data and the computer reads the data from the local hard drive for example analysis.

    1. in no USB before the interface, the computer has a strong dependence on the internal hard disk, and this relationship is written dead, control in the computer itself.
  1. usb After the interface, the computer through the usb interface to the external storage device dependencies, completely to the user management, control is also in the hands of the user, whether through usb interface what is connected (mobile, mobile hard disk, u disk), the computer can read data successfully. This is what is often said about the meaning of inversion of control. The basic idea of the realization of control inversion is that the process of the computer reading data through the mobile device is the dependence of the computer on the external device, through the usb interfaces are injected into the two.

IOC The best way to generate objects is to reflect, Spring The core of the idea is ioc,ioc+ reflection is a successful way to implement dependency injection.

in the Itoo in the University Cloud Platform system:

in the first edition of the University cloud Platform service-side framework, the use of a large number of factories and reflection, to achieve BD layers of dependency and wcf,b the dependency of the layer. In the second edition of the service Framework, the factory was removed and spring was referenced, and the dependencies of each layer were given to the IOC container.

  <spring>    <context>      <!--<resourceuri= "Assembly://springlover/springlover/objects.xml" />-->      <!--<resourceuri= "~/objects.xml"/>      <resourceuri= "~/objects02.xml"/>      <resourceuri= "~/objects.xml"/>      <resourceuri= "file://objects.xml"/>--> <resourceuri=      " Config://spring/objects "/>    </context>    <objectsxmlns=" Http://www.springframework.net ">     <objectid= "BASICROOMBLL" type= "Itoo. Basicplace.bll.basicroombll,itoo. Basicplace.bll "singleton=" false "/>      <!--B-level comments--    </objects>  </spring>


Procedure for invoking a class

<summary>        ///Call B-building type///        </summary>        ibuildingtypebll BUILDINGTYPEBLL = Springhelper.getobject<ibuildingtypebll> ("BASICBUILDINGTYPEBLL");

I hope every child can give his mother what he should eat.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

You can eat whatever you like.--IOC container

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.