Skip to content

Commit

Permalink
Added explicit setting of client session handle via parameter. (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
nscheibe committed Nov 30, 2022
1 parent d2c7b75 commit eee45ff
Show file tree
Hide file tree
Showing 10 changed files with 1,989 additions and 1,908 deletions.
671 changes: 335 additions & 336 deletions src/Transactions.Tests/TransactionCollectionTests.cs

Large diffs are not rendered by default.

87 changes: 44 additions & 43 deletions src/Transactions/MongoDbEnlistmentScope.cs
@@ -1,63 +1,64 @@
using System.Transactions;
using MongoDB.Driver;

namespace MongoDB.Extensions.Transactions
namespace MongoDB.Extensions.Transactions;

public class MongoDbEnlistmentScope : IEnlistmentNotification
{
public class MongoDbEnlistmentScope : IEnlistmentNotification
{
public delegate void Unregister();
public delegate void Unregister();

private readonly Unregister _unregister;
private readonly IClientSessionHandle _sessionHandle;

private readonly Unregister _unregister;
private readonly IClientSessionHandle _sessionHandle;
public MongoDbEnlistmentScope(
IClientSessionHandle sessionHandle,
Unregister unregister)
{
_sessionHandle = sessionHandle;
_unregister = unregister;
}

public MongoDbEnlistmentScope(IClientSessionHandle sessionHandle, Unregister unregister)
public void Commit(Enlistment enlistment)
{
try
{
_sessionHandle = sessionHandle;
_unregister = unregister;
_sessionHandle.CommitTransaction();
enlistment.Done();
}

public void Commit(Enlistment enlistment)
finally
{
try
{
_sessionHandle.CommitTransaction();
enlistment.Done();
}
finally
{
_unregister();
}
_unregister();
}
}

public void InDoubt(Enlistment enlistment)
public void InDoubt(Enlistment enlistment)
{
try
{
try
{
_sessionHandle.AbortTransaction();
enlistment.Done();
}
finally
{
_unregister();
}
_sessionHandle.AbortTransaction();
enlistment.Done();
}

public void Prepare(PreparingEnlistment preparingEnlistment)
finally
{
preparingEnlistment.Prepared();
_unregister();
}
}

public void Prepare(PreparingEnlistment preparingEnlistment)
{
preparingEnlistment.Prepared();
}

public void Rollback(Enlistment enlistment)
public void Rollback(Enlistment enlistment)
{
try
{
_sessionHandle.AbortTransaction();
enlistment.Done();
}
finally
{
try
{
_sessionHandle.AbortTransaction();
enlistment.Done();
}
finally
{
_unregister();
}
_unregister();
}
}
}

0 comments on commit eee45ff

Please sign in to comment.