I'm trying to use the Castle NHibernate Facility with the AutoTx Facility. As a test, I'm throwing an exception in the middle of my service, to make sure the transaction is rolled back. However, the data is still persisted in the database.
My service interface, IActivityService
using the TransactionAttribute:
public interface IActivityService
{
[Transaction]
Activity CreateActivity(Activity activity);
}
The implementation of CreateActivity
. I'm throwing an exception here, expecting the data added in AddActivity
to be rolled back:
public virtual Activity CreateActivity(Activity activity)
{
activityDAO.AddActivity(activity);
throw new Exception("This should rollback the transaction");
return activity;
}
Implementation of AddActivity
. SessionManager
is an injected ISessionManager
.
public void AddActivity(Activity activity)
{
using (ISession session = SessionManager.OpenSession())
{
session.Save(activity);
}
}
Finally, here's how I'm configuring the windsor container. The NHibernateInstaller
is straight from the guide, with my fluent nhibernate configuration swapped in:
container = new WindsorContainer().Install(FromAssembly.This());
// set up ISessionManager injection for DAOs
container
.AddFacility<AutoTxFacility>()
.Register(Component
.For<INHibernateInstaller>()
.ImplementedBy<NHibernateInstaller>()
.LifeStyle.Singleton)
.AddFacility<NHibernateFacility>(f =>
f.DefaultLifeStyle = DefaultSessionLifeStyleOption.SessionPerWebRequest);
The configuration seemed fairly straightforward, but I can't figure out what I'm missing. Thanks for any help.