(Environment:. net1.1, spring.net 1.2 Preview)
1.Set property Injection
Our components often require property injection of the set type. For example, my hook component needs to be injected with a set, and the elements in the Set (INT type) specifies the types of messages to be intercepted. We often use ilist to handle collection problems:
# Region hooklist where elements are of the integer type
Private ilist hooklist = new arraylist ();
Public ilist hooklist
{
Set
{
This. hooklist = value;
}
}
# Endregion
The corresponding spring configuration snippets are as follows: <property name = "hooklist">
<List>
<Value> 1 </value>
<Value> 3 </value>
<Value> 2 </value>
</List>
</Property>
After the IOC container is assembled according to the configuration, it is found that the elements in the hooklist are of the string type. Because the ilist can accommodate any type of objects, spring adopts the default configuration type-string. As you can't imagine, the following code will throw an exception during runtime:
Foreach (INT key in this. hookedlist)
After some thinking and experimentation, the conclusion is as follows:
(1) If the elements in the set attribute to be set are of the string type, it is good to use ilist.
(2) If it is another type, the type of the attribute set is preferably an array of the target type, that is, the preceding attribute can be changed to: # region hooklist
Private int [] hooklist = new int [0];
Public int [] hooklist
{
Set
{
This. hooklist = value;
}
}
# Endregion
After the attribute definition is modified, the configuration file and the code that uses it can work normally without any modifications.
2.2006-06-12 if an error occurs when spring assembles an object based on the configuration file, spring will call the dispose method of each instantiated object in sequence before throwing an exception, then throw system. configuration. configurationerrorsexception.
If your program is calling Spring. context. support. contextregistry. getcontext () does not respond, so it is likely that manualresetevent is included in the dispose method of an instance. waitone (-1, true.
3.2006-06-13 read objects from multiple xml configuration files
There are three types of configuration files that can be used to assemble components:
(1) app. config provides the following instructions in the context configuration section: <resource uri = "config: // spring/objects"/>
(2) The xml configuration file embedded in the Assembly. In the context configuration section, give the following instructions: <resource uri = "assembly: // springnestconfigtest/appcontext. xml"/>
Format: uri = "assembly: // myassembly/myproject/appcontext. xml "/
(3) Common xml configuration file under appbase. In the context configuration section, give the following instructions: <resource uri = "file: // objects. xml"/>
Combined: <context>
<! -- Using section in APP. config -->
<Resource uri = "config: // spring/objects"/>
<! -- Using embedded assembly configuration file -->
<Resource uri = "assembly: // springnestconfigtest/appcontext. xml"/>
<! -- Using common configuration file -->
<Resource uri = "file: // objects. xml"/>
</Context>
For example, the content of objects. XML is: <? XML version = "1.0" encoding = "UTF-8"?>
<Objects xmlns = "http://www.springframework.net">
<Object name = "esbnetmessagehook" type = "esframework. Network. esbnetmessagehook, esframework">
</Object>
<Object name = "agiletcp" type = "esframework. Network. tcp. asyntcp, esframework">
<Property name = "esblogger"Ref = "esblogger"/>
</Object>
</Objects>
The esblogger object is defined in appcontext. xml.