Main content
1. The way of life treatment
2. Customizing the way Life is handled
3. Life cycle Processing
A The way of life treatment
We usually create an instance of a component using the New keyword, so that every time we create it, we use the singleton pattern if we want to have only one instance of the component. In the castle IOC, it supports our control over the instance of a component, which means that we can transparently manage how many instances a component has. The Castle IOC container provides the following kinds of life-processing methods:
L Singleton: Only one instance of a component is created, and all requested clients use the same instance, which is also the default processing method of the Castle IOC container.
L Transient: This approach is the same as the effect we usually use new, for each request is a new instance.
L Perthread: For each thread, the singleton is used, which means that each thread gets the same instance.
L Pooled: How the object pool is handled, and the instances that are no longer needed are saved to an object pool.
Custom: Customizing the way Life is handled.
There are two ways we can specify the life-handling of a component, or singleton if not specified:
1. Using configuration Files
<!--出处:http://terrylee.cnblogs.com-->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<components>
<component id="comp1" lifestyle="transient">
<parameters>
<para>component1 para</para>
</parameters>
</component>>
</components>
</configuration>
2. Use attribute attributes
//出处:http://terrylee.cnblogs.com
[Transient]
public class MyComponent
{
public MyComponent()
{
//
}
public MyComponent(string _Str)
{
//
}
}