Chapter 4 how spring. Net manages your ___ object, object factory, and application context

Source: Internet
Author: User

In the previous chapter, we introduced the concept of dependency injection and control inversion, as well as a self-built spring. NET environment. Through these operations, we know that the core of spring. NET is to use the idea of dependency injection or control inversion to manage business objects and reduceProgramDependency coupling. This time, I will take a look at how spring. Net manages our classes.

4.1Introduction to objects, object factories, and application context

In the previous chapter, we mentioned objects, object factory, and application context. We also know that you can use these interfaces to manage objects. Next we will introduce them in detail.

Spring. Core Assembly is the basis for managing objects in the IOC container of spring. net. The iobjectfactory, iapplicationcontext, and iobjectdefinition interfaces are provided in the spring. core program to help us manage objects.

The iobjectfactory interface provides an advanced configuration mechanism for spring. net. You can use XML, txt, and many other types of files to configure object information at will.

The iapplicationcontext interface extends iobjectfactory and provides functions for Aspect-oriented programming (AOP) and message resource processing.

In short, the iobjectfactory interface provides the basic functions of the configuration framework. The iapplicationcontext interface also extends many enterprise-level functions. It can be said that iapplicationcontext is the superset of iobjectfactory, which has all the functions and behaviors of iobjectfactory.

4.2 iobjectfactoryAnd iapplicationcontextComparison

Iobjectfactory is the real container for initialization, configuration, and management objects. In fact, all extended containers implement the iobjectfactory interface, such as spring. objects. factory. XML. the xmlobjectfactory class also implements the iobjectfactory interface. Objects often collaborate with each other, that is, they are dependent on each other. These dependencies can be reflected through the configuration of iobjectfactory. (Note: Some configurations are invisible, such as calling methods between objects during runtime .)

(Yes: Definition of iobjectfactory)

(Yes: Definition of iapplicationcontext)

We can see that spring. Context. iapplicationcontext implements the iobjectfactory interface, and there are many derived classes in iobjectfactory. Here there are only a few commonly used classes, which are not described here. If you are interested, you can learn more.

(It is a derived interface of iobjectfactory or a derived class)

As mentioned above, the iapplicationcontext interface is a superset of iobjectfactory. In actual development, I usually use iapplicationcontext as the container for spring. Net dependency injection.

4.3Object Definition

We have mentioned spring. Net object management before, but we have never said how to define objects. In spring. Net containers, we often use XML files to define objects, although TXT and other file types can also define objects. However, here I only record common XML files to define objects. For example, object. XML in cnbloglesson_3_3 is the XML file used to define objects.

 1   <?  XML version = "1.0" encoding = "UTF-8"  ?>  2   <  Objects  Xmlns  = "Http://www.springframework.net"  >  3     <  Object ID  = "Readerdal"  Type  = "Cnbloglesson_3_3.readerdal, cnbloglesson_3_3"  >  4     </  Object  >  5   </  Objects  > 

The parent node of all objects is an objects label, and the xmlns attribute indicates that it belongs to spring.. Net configuration file (this attribute must be assigned; otherwise, spring.. Net parser). One or more object labels can be added to the objects tag.

Id indicates the ID of the object. We can obtain this object through this ID. For example:

1 //Use iapplicationcontext to configure2Iapplicationcontext context =Contextregistry. getcontext ();3Dal = (ireaderdal) Context. GetObject ("Readerdal");

Type indicates the type of the object, which is generally represented by the full name of the class and namespace name.

For example, type = "cnbloglesson_3_3.readerdal, cnbloglesson_3_3"

They have many attributes. In this section, we only introduce two attributes (ID, type). The remaining attributes are described in the following sections.

This note may be a little too long, but there is only one simple purpose, that is, let people understand spring. net container (including iapplicationcontext, iobjectfactory) and object, and the relationship between them.

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.