Spring.net (2) Environment setup: (1) Example explanation and Expansion

Source: Internet
Author: User

In the above example, a simple example of spring.net control inversion is implemented:

However, there may be some questions.

What does the configuration file in the example mean:

For the configuration rules of app. config, refer to the configuration details of web. config.

  

                  

After the node processor is registered, the <spring> node in the configuration file takes effect.

<Context> the type attribute of a node is optional. In Windows applications, the default value is Spring. Context. Support. XmlApplicationContext.

In

In the previous example, I used:

<Resource uri = "file: // objects. xml"> </resource>
To specify access to files. Add the configuration information in objects. xml to resource.
There are two common uri methods:

Assembly: // assembly name/namespace/File Name: load the xml file of the embedded Resource
Config: // spring/objects directly use the configuration information in the configuration <objects xmlns = "http://www.springframework.net"/> in app. config:

It is worth noting that xmlns = "http://www.springframework.net" in xml configuration must be added:

In the previous blog, container instantiation:
IApplicationContext ctx = ContextRegistry.GetContext();

Actual physical path
  IResource input =  FileSystemResource();              IObjectFactory factory =  XmlObjectFactory(input);

Search for configuration files under the Assembly

 [] xmlFiles =  = =

Define objects in objects. xml:

Where:

Object Identifier (id and name ):

An object has one or more IDs, which should be unique in the container. An Object usually has only one identifier. If multiple identifiers are specified, the rest are considered as aliases.

When defining an object in xml, the id or name attribute is used to define the object identifier. Each object must define at least one identifier using the id or name attribute. The id attribute allows you to specify a unique id for the object definition. in the shcema document of. NET, the id is identified as the ID attribute of the XML element. The XML Parser can verify when other elements reference it. When configuring the object identifier, the id attribute should be used first. However, the id property value cannot contain any characters that are not allowed by the xml id. If you must use these characters, you should use the name attribute. In the name attribute, you can also use commas or semicolons to specify one or more aliases for the object.

Singleton and Prototype:

Objects can be deployed in two modes: singleton and non-singleton (or prototype, but it is not suitable for use here ). When an object is defined as singleton, there is only one shared instance in the container, if you request this object by id or alias at any time, a reference to this shared instance is returned (that is, this object will be created only once ).

When a non-singleton or prototype is deployed, a new instance is created for each request object. In some cases, if you need to return individual user objects or other objects for each user, the non-singlton deployment mode is ideal.

If it is not explicitly specified, the deployment mode of the object is singleton by default. Note that the non-singleton (prototype) mode will allow Spring. NET to create a new instance for each request object, which may not be our expected behavior. Therefore, do not use the prototype unless absolutely required.

Property

For the property strength of an object, you can directly specify name = "property name" value = "property value"

<typeAliases> <alias name= type= /> <alias name= type= /></typeAliases>

Then, the following object definition:

< id== />

This can be shortened:

  

< id== />

Or shorter:

< id== />

 

 

The following files are frequently used in Spring. NET frameworks:

Common. Logging. dll (required) Spring. Core. dll (required) Spring. Data. dllSpring. Aop. dll (optional) Spring. Data. NHibernate21.dllSpring. Web. dll

 

Related Article

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.