Home

Castle Stronghold

Automatic Transaction Management Facility

The Automatic Transaction Management Facility performs declarative transaction management for your classes using interceptors.

This facility uses the Castle Transaction Service.

Facility Summary
Uses ProxyYes
Requires configurationOptionally
Uses attributeOptionally
Version1.0 RC 1
Maturity levelHigh

Introduction

This facility manages the creation of Transactions and the associated commit or rollback, depending on whether the method throws an exception or not.

Transactions are logical. It is up the other integration to be transaction aware and enlist its resources on it.

Quick start

This facility usually works together with others facilities, as it requires an implementation of ITransactionManager. Currently the ActiveRecord Integration Facility, NHibernate facility and iBatis.Net facility implement the ITransactionManager.


<configuration>

    <facilities>
    
        <facility 
            id="atm" 
            type="Castle.Facilities.AutomaticTransactionManagement.TransactionFacility, Castle.Facilities.AutomaticTransactionManagement" />
    
    </facilities>

</configuration>

Defining transaction behavior on components

You can use attributes or the configuration file to associate transaction information with your components.

Using attributes


using Castle.Services.Transaction;

[Transactional]
public class BusinessClass
{
    public void Load(int id)
    {
        ...
    }

    // note the "virtual" 
    [Transaction(TransactionMode.Requires)]
    public virtual void Save(Data data)
    {
        ...
    }
}

Using configuration


<configuration>

    <components>

        <component 
            id="mycomp" 
            type="Namespace.BusinessClass, AssemblyName"
            isTransactional="true">
        
            <transaction>
                <method name="Save" />
                <method name="Create" />
            </transaction>
        
        </component>
        
    </components>

</configuration>
Warning

If you are registering the component without an interface as a service you must make the methods virtual in order to being intercepted. Please refer to DynamicProxy documentation for more information about it.

TransactionMode

Required Assemblies

Google
Search WWW Search castleproject.org