Spring. net {
Function onclick ()
{
Tagshow (Event)
}
} "> Interface to control the behavior of objects in the container. When it comes to object behavior, we need to mention the object lifecycle control. Similar to winform development, in the form lifecycle, the load method is the loading method of form and the dispose method is the destroy method of form. Spring. Net can perfectly meet these needs.
I. lifecycle Interface
When using spring. net {
Function onclick ()
{
Tagshow (Event)
}
} "> How to initialize and destroy a framework {
Function onclick ()
{
Tagshow (Event)
}
} "> The following solutions may help you with the trouble of hosting resources (such as database connections.
1. Initialization
Inherit the spring. Objects. Factory. iinitializingobject interface or {
Function onclick ()
{
Tagshow (Event)
}
} "> Configure the init-method attribute of the object node. The IOC framework of spring. NET will call the configured initialization method after the object is instance.
2. Destruction
Inherit the system. idisposable interface or configure the destroy-method attribute on the object node. Spring. NET will call it when the container is destroyed.
Implementation Code:
Person
- Public class person
- {
- Public void Init ()
- {
- Console. writeline ("I have grown up ");
- }
- Public void destroy ()
- {
- Console. writeline ("I am aging ");
- }
- }
- <! -- Lifecycle interface -->
- <Object ID = "person" type = "springnetprocessor. Person, springnetprocessor"
- Init-method = "init" Destroy-method = "Destroy"/>
Copy code
Ii. Definition of abstract objects and sub-objects
The object definition may contain a large amount of information, such as container-related information (such as the initialization method and static factory method name), constructor parameters, and attribute values. A sub-object definition is an object definition that inherits configuration data from a parent object definition. Sub-object definitions can be rewritten or added as needed. Defining the parent object and sub-object may save a lot of input work. Actually this is {
Function onclick ()
{
Tagshow (Event)
}
} "> In design mode {
Function onclick ()
{
Tagshow (Event)
}
} "> Template mode. In my opinion, the coupling between "subclass" and "parent class" can be solved.
Set the parent attribute in the object node to indicate that it is an inheritance relationship rather than an inheritance of positive meaning.
Implementation Code:
- <! -- Abstract object definition and sub-object definition -->
- <Object ID = "parent" type = "springnetprocessor. Parent, springnetprocessor" abstract = "true">
- <Property name = "name" value = "parent"/>
- </Object>
- <Object ID = "child" type = "springnetprocessor. Child, springnetprocessor" parent = "parent"/>
- Public abstract class parent
- {
- Public string name {Get; set ;}
- }
- Public class child
- {
- Public string name {Get; set ;}
- }
Copy code
We can see that the Child class does not inherit the parent class.
Output result: