@@ -1,5 +1,4 @@ | |||
using System.Data; | |||
using System.Diagnostics; | |||
using System.Diagnostics; | |||
using MongoDB.Driver; | |||
// ReSharper disable once CheckNamespace | |||
@@ -36,7 +35,7 @@ namespace DotNetCore.CAP | |||
public override void Dispose() | |||
{ | |||
(DbTransaction as IDbTransaction)?.Dispose(); | |||
(DbTransaction as IClientSessionHandle)?.Dispose(); | |||
} | |||
} | |||
@@ -49,11 +48,25 @@ namespace DotNetCore.CAP | |||
{ | |||
dbTransaction.StartTransaction(); | |||
} | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
return transaction; | |||
} | |||
} | |||
public static IClientSessionHandle BeginAndJoinToTransaction(this IClientSessionHandle clientSessionHandle, | |||
ICapPublisher publisher, bool autoCommit = false) | |||
{ | |||
var capTrans = publisher.Transaction.Begin(clientSessionHandle, autoCommit); | |||
return new CapMongoDbClientSessionHandle(capTrans); | |||
} | |||
public static IClientSessionHandle StartAndJoinToTransaction(this IMongoClient client, | |||
ICapPublisher publisher, bool autoCommit = false) | |||
{ | |||
var clientSessionHandle = client.StartSession(); | |||
return BeginAndJoinToTransaction(clientSessionHandle, publisher, autoCommit); | |||
} | |||
} | |||
} |
@@ -55,7 +55,6 @@ namespace DotNetCore.CAP | |||
public static ICapTransaction Begin(this ICapTransaction transaction, | |||
IDbContextTransaction dbTransaction, bool autoCommit = false) | |||
{ | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
@@ -66,7 +65,7 @@ namespace DotNetCore.CAP | |||
ICapPublisher publisher, bool autoCommit = false) | |||
{ | |||
var trans = database.BeginTransaction(); | |||
var capTrans = publisher.Transaction.Begin(trans); | |||
var capTrans = publisher.Transaction.Begin(trans, autoCommit); | |||
return new CapEFDbTransaction(capTrans); | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
using System.Data; | |||
using System.Diagnostics; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Storage; | |||
// ReSharper disable once CheckNamespace | |||
@@ -50,7 +51,7 @@ namespace DotNetCore.CAP | |||
public static class CapTransactionExtensions | |||
{ | |||
public static ICapTransaction Begin(this ICapTransaction transaction, | |||
IDbTransaction dbTransaction, bool autoCommit = false) | |||
IDbContextTransaction dbTransaction, bool autoCommit = false) | |||
{ | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
@@ -58,14 +59,12 @@ namespace DotNetCore.CAP | |||
return transaction; | |||
} | |||
public static ICapTransaction Begin(this ICapTransaction transaction, | |||
IDbContextTransaction dbTransaction, bool autoCommit = false) | |||
public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database, | |||
ICapPublisher publisher, bool autoCommit = false) | |||
{ | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
return transaction; | |||
var trans = database.BeginTransaction(); | |||
var capTrans = publisher.Transaction.Begin(trans, autoCommit); | |||
return new CapEFDbTransaction(capTrans); | |||
} | |||
} | |||
@@ -1,5 +1,6 @@ | |||
using System.Data; | |||
using System.Diagnostics; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Storage; | |||
// ReSharper disable once CheckNamespace | |||
@@ -50,23 +51,20 @@ namespace DotNetCore.CAP | |||
public static class CapTransactionExtensions | |||
{ | |||
public static ICapTransaction Begin(this ICapTransaction transaction, | |||
IDbTransaction dbTransaction, bool autoCommit = false) | |||
IDbContextTransaction dbTransaction, bool autoCommit = false) | |||
{ | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
return transaction; | |||
} | |||
public static ICapTransaction Begin(this ICapTransaction transaction, | |||
IDbContextTransaction dbTransaction, bool autoCommit = false) | |||
public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database, | |||
ICapPublisher publisher, bool autoCommit = false) | |||
{ | |||
transaction.DbTransaction = dbTransaction; | |||
transaction.AutoCommit = autoCommit; | |||
return transaction; | |||
var trans = database.BeginTransaction(); | |||
var capTrans = publisher.Transaction.Begin(trans, autoCommit); | |||
return new CapEFDbTransaction(capTrans); | |||
} | |||
} | |||