Have a look to the transaction factories - those are pluggable. /Oskar
2012/12/1 SirSirAaron <[email protected]>: > What is the best way to override ISession.BeginTranscation and > ISession.Transaction? > > I would like to wrap NHibernate's ITransaction with Rx to observe when > transactions rollback and commit. > > public interface IObservableTransaction : ITransaction > { > IDisposable SubscribeToCommit(Action<ITransaction> actionOnCommit); > IDisposable SubscribeToRollback(Action<ITransaction> > actionOnRollBack); > } > > public class ObservableTransaction : IObservableTransaction > { > private readonly ITransaction _transaction; > private readonly Subject<ITransaction> _commitSubject = new > Subject<ITransaction>(); > private readonly Subject<ITransaction> _rollbackSubject = new > Subject<ITransaction>(); > > public ObservableTransaction(ITransaction transaction) > { > _transaction = transaction; > } > > public void Dispose() > { > _transaction.Dispose(); > _commitSubject.Dispose(); > } > > public void Begin() > { > _transaction.Begin(); > } > > public void Begin(IsolationLevel isolationLevel) > { > _transaction.Begin(isolationLevel); > } > > public IDisposable SubscribeToCommit(Action<ITransaction> > actionOnCommit) > { > return _commitSubject.Subscribe(actionOnCommit); > } > > public void Commit() > { > _transaction.Commit(); > _commitSubject.OnNext(this); > _commitSubject.OnCompleted(); > _rollbackSubject.OnCompleted(); > } > > public IDisposable SubscribeToRollback(Action<ITransaction> > actionOnRollBack) > { > return _rollbackSubject.Subscribe(actionOnRollBack); > } > > public void Rollback() > { > _transaction.Rollback(); > _rollbackSubject.OnNext(this); > _commitSubject.OnCompleted(); > _rollbackSubject.OnCompleted(); > } > > public void Enlist(IDbCommand command) > { > _transaction.Enlist(command); > } > > public void RegisterSynchronization(ISynchronization > synchronization) > { > _transaction.RegisterSynchronization(synchronization); > } > > public bool IsActive > { > get { return _transaction.IsActive; } > } > > public bool WasRolledBack > { > get { return _transaction.WasRolledBack; } > } > > public bool WasCommitted > { > get { return _transaction.WasCommitted; } > } > } > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/nhusers/-/tkW9xpGRxQoJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
