TheProgramSet:
- Castle. Facilities. automatictransactionmanagement
- Castle. Services. Transactions
- Castle. dynamicproxy
- Castle. Core
1. Configuration
Windsorcontainer container = New Windsorcontainer (store );
Container. addfacility ( " Auto. Transaction " , New Transactionfacility ());
Or
< Facilities >
< Facility ID = "Transaction" Type = "Castle. Facilities. automatictransactionmanagement. transactionfacility, Castle. Facilities. automatictransactionmanagement" />
</ Facilities >
2. Code Use automatic transaction management Using System;
Using System. collections;
Using System. Collections. Generic;
Using System. text;
Using FeS. persistence;
Using FeS. domain. Common;
Using FeS. Service. interface;
Using Castle. Facilities. ibatisnetintegration;
Using Castle. Services. transaction;
Using Castle. Facilities. automatictransactionmanagement;
Namespace FeS. Service. Implement
{
[Transactional]
[Usesautomaticsessioncreation]
Public Class Commonservice: icommonservice
{
Private Commonsqlmapdao _ common;
Public Commonservice (commonsqlmapdao common)
{
_ Common=Common;
}
[Transaction (transactionmode. Requires)]
Public Bool Login ( String Empcode, String Password, Ref Employees EMP)
{
EMP = _ Common. getemployeedetailbypassword (empcode, password );
If (EMP = Null )
{
Return False;
}
Else
{
Return True;
}
}
[Transaction (transactionmode. Requires)]
Public Void Insertemppages (emppages pages)
{
_ Common. deleteemppages (pages. Eid );
_ Common. addemppages (pages );
}
[Transaction (transactionmode. Requires)]
Public Void Insertemppages (arraylist Al, Int EID)
{
_ Common. deleteemppages (EID );
For ( Int I = 0 ; I < Al. Count; I ++ )
{
Emppages pages=(Emppages) al [I];
_ Common. addemppages (pages );
}
}
}
}
Note: If the component you use for automatic transaction management in container registration is not registered as an interface, the method for automatic transaction management must be declared as virtual.
You can also use automatic transaction management in the configuration file of the container registration component:
< Configuration >
< Components >
< Component
ID = "Common"
Service = "FES. Service. interface. icommonservice, FeS. Service"
Type = "FES. Service. Implement. commonservice, FeS. Service" Istransactional = "True" >
< Transaction >
< Method Name = "Login" />
< Method Name = "Insertemppages" />
</ Transaction >
</ Component >
</ Components >
</ Configuration >