我正在使用 Spring .NET 和 NHibernate 以及 ASP .NET MVC。
最近我决定将事务管理与 Spring 集成。我了解 Spring 提供了一种使用服务上的 [Transaction()] 属性轻松集成事务的方法。我得到了这个工作。
我的旧架构是通过使用 AOP 的建议拦截对服务的调用,并检查您是否被允许调用此方法。
CALL --> Tx Advice --> Permission Advice --> Service --> 执行逻辑 --> Commit/Rollback Tx in Tx Advice --> End CALL。
现在,由于我的服务方法上的 Transaction() 属性,我不再需要 Tx Advice。
但是,我如何才能使事务在进入 PermissionAdvice 之前开始。
文件:services.xml
<object id="BusinessLogicServiceBase" type="Winito.Server.Services.Impl.BusinessLogicService, Winito.Server">
<property name="ObjectPersistenceManager" ref="ObjectPersistenceManager" />
<property name="StatisticsStandingsManager" ref="StatisticsStandingsManager" />
....
</object>
<tx:attribute-driven/>
文件:Dao.xml
<object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object>
<!-- Database and NHibernate Configuration -->
<!-- SqlServer-2.0 -->
<db:provider id="DbProvider" provider="System.Data.SqlClient" connectionString="" />
<!-- NHibernate Configuration -->
<object id="NHibernateSessionFactory" type="Winito.Data.Base.NHibernate.CustomLocalSessionFactoryObject, Winito.Data.Base">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Winito.Core</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<entry key="use_proxy_validator" value="false" />
<entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<entry key="connection.isolation" value="ReadCommitted" />
<!--<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache</property>-->
<!--<property name="cache.use_second_level_cache">true</property>-->
<entry key="command_timeout" value="340" />
<entry key="use_outer_join" value="true" />
<entry key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
</dictionary>
</property>
<!-- provides integation with Spring's declarative transaction management features -->
<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>
<!-- Transaction Management Strategy - local database transactions -->
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate30">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>
<!-- Exception translation object post processor -->
<object type="Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor, Spring.Data"/>
旧代码:
<object id="BusinessLogicService" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="target" ref="BusinessLogicServiceBase" />
<property name="interceptorNames">
<list>
<!-- <value>TimingAdvice</value> -->
<value>TransactionalAdvice</value>
<value>PermissionAdviceBusinessLogic</value>
</list>
</property>
</object>