Reliable integration with other systems is a common business requirement. When these systems report error conditions, it's necessary to roll back not only the local database work, but perhaps the work of multiple transactional resources. In this recipe, I'll show you how to use Microsoft's TransactionScope and NHibernate to achieve this goal.
Create a new console application project.
Add references to the Eg.Core
project in Chapter 1, NHibernate.dll
, and NHibernate.ByteCode.Castle.dll
.
Get the console application ready by following the Configuring NHibernate with App.config and Configuring log4net recipes in Chapter 2.
Add a reference to
System.Transaction
.Add a public interface named
IReceiveProductUpdates
with the following three methods:void Add(Product product); void Update(Product product); void Remove(Product product);
Add a public class named
WarehouseFacade
with this code:public class WarehouseFacade : IReceiveProductUpdates...