@@ -25,9 +25,7 @@ namespace DotNetCore.CAP.MongoDB | |||||
services.AddSingleton<CapStorageMarkerService>(); | services.AddSingleton<CapStorageMarkerService>(); | ||||
services.AddSingleton<IDataStorage, MongoDBDataStorage>(); | services.AddSingleton<IDataStorage, MongoDBDataStorage>(); | ||||
services.AddSingleton<IStorageInitializer, MongoDBStorageInitializer>(); | |||||
services.AddTransient<ICapTransaction, MongoDBCapTransaction>(); | |||||
services.AddSingleton<IStorageInitializer, MongoDBStorageInitializer>(); | |||||
services.Configure(_configure); | services.Configure(_configure); | ||||
@@ -81,7 +81,7 @@ namespace DotNetCore.CAP | |||||
ICapPublisher publisher, bool autoCommit = false) | ICapPublisher publisher, bool autoCommit = false) | ||||
{ | { | ||||
var clientSessionHandle = client.StartSession(); | var clientSessionHandle = client.StartSession(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MongoDBCapTransaction>(publisher.ServiceProvider); | |||||
var capTrans = publisher.Transaction.Value.Begin(clientSessionHandle, autoCommit); | var capTrans = publisher.Transaction.Value.Begin(clientSessionHandle, autoCommit); | ||||
return new CapMongoDbClientSessionHandle(capTrans); | return new CapMongoDbClientSessionHandle(capTrans); | ||||
} | } | ||||
@@ -26,7 +26,6 @@ namespace DotNetCore.CAP | |||||
services.AddSingleton<IDataStorage, MySqlDataStorage>(); | services.AddSingleton<IDataStorage, MySqlDataStorage>(); | ||||
services.TryAddSingleton<IStorageInitializer, MySqlStorageInitializer>(); | services.TryAddSingleton<IStorageInitializer, MySqlStorageInitializer>(); | ||||
services.AddTransient<ICapTransaction, MySqlCapTransaction>(); | |||||
//Add MySqlOptions | //Add MySqlOptions | ||||
services.Configure(_configure); | services.Configure(_configure); | ||||
@@ -121,7 +121,7 @@ namespace DotNetCore.CAP | |||||
ICapPublisher publisher, bool autoCommit = false) | ICapPublisher publisher, bool autoCommit = false) | ||||
{ | { | ||||
var trans = database.BeginTransaction(); | var trans = database.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MySqlCapTransaction>(publisher.ServiceProvider); | |||||
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | ||||
return new CapEFDbTransaction(capTrans); | return new CapEFDbTransaction(capTrans); | ||||
} | } | ||||
@@ -142,7 +142,7 @@ namespace DotNetCore.CAP | |||||
} | } | ||||
var dbTransaction = dbConnection.BeginTransaction(); | var dbTransaction = dbConnection.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MySqlCapTransaction>(publisher.ServiceProvider); | |||||
return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | ||||
} | } | ||||
} | } |
@@ -27,7 +27,6 @@ namespace DotNetCore.CAP | |||||
services.AddSingleton<IDataStorage, PostgreSqlDataStorage>(); | services.AddSingleton<IDataStorage, PostgreSqlDataStorage>(); | ||||
services.AddSingleton<IStorageInitializer, PostgreSqlStorageInitializer>(); | services.AddSingleton<IStorageInitializer, PostgreSqlStorageInitializer>(); | ||||
services.AddTransient<ICapTransaction, PostgreSqlCapTransaction>(); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -124,7 +124,7 @@ namespace DotNetCore.CAP | |||||
if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); | if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); | ||||
var dbTransaction = dbConnection.BeginTransaction(); | var dbTransaction = dbConnection.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<PostgreSqlCapTransaction>(publisher.ServiceProvider); | |||||
return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | ||||
} | } | ||||
@@ -139,7 +139,7 @@ namespace DotNetCore.CAP | |||||
ICapPublisher publisher, bool autoCommit = false) | ICapPublisher publisher, bool autoCommit = false) | ||||
{ | { | ||||
var trans = database.BeginTransaction(); | var trans = database.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<PostgreSqlCapTransaction>(publisher.ServiceProvider); | |||||
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | ||||
return new CapEFDbTransaction(capTrans); | return new CapEFDbTransaction(capTrans); | ||||
} | } | ||||
@@ -29,7 +29,6 @@ namespace DotNetCore.CAP | |||||
services.AddSingleton<DiagnosticProcessorObserver>(); | services.AddSingleton<DiagnosticProcessorObserver>(); | ||||
services.AddSingleton<IDataStorage, SqlServerDataStorage>(); | services.AddSingleton<IDataStorage, SqlServerDataStorage>(); | ||||
services.AddSingleton<IStorageInitializer, SqlServerStorageInitializer>(); | services.AddSingleton<IStorageInitializer, SqlServerStorageInitializer>(); | ||||
services.AddTransient<ICapTransaction, SqlServerCapTransaction>(); | |||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, DiagnosticRegister>()); | services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, DiagnosticRegister>()); | ||||
services.Configure(_configure); | services.Configure(_configure); | ||||
@@ -46,14 +46,14 @@ namespace DotNetCore.CAP | |||||
if (dbTransaction == null) throw new ArgumentNullException(nameof(DbTransaction)); | if (dbTransaction == null) throw new ArgumentNullException(nameof(DbTransaction)); | ||||
} | } | ||||
var transactionKey = ((SqlConnection) dbTransaction.Connection).ClientConnectionId; | |||||
var transactionKey = ((SqlConnection)dbTransaction.Connection).ClientConnectionId; | |||||
if (_diagnosticProcessor.BufferList.TryGetValue(transactionKey, out var list)) | if (_diagnosticProcessor.BufferList.TryGetValue(transactionKey, out var list)) | ||||
{ | { | ||||
list.Add(msg); | list.Add(msg); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
var msgList = new List<MediumMessage>(1) {msg}; | |||||
var msgList = new List<MediumMessage>(1) { msg }; | |||||
_diagnosticProcessor.BufferList.TryAdd(transactionKey, msgList); | _diagnosticProcessor.BufferList.TryAdd(transactionKey, msgList); | ||||
} | } | ||||
} | } | ||||
@@ -163,11 +163,10 @@ namespace DotNetCore.CAP | |||||
ICapPublisher publisher, bool autoCommit = false) | ICapPublisher publisher, bool autoCommit = false) | ||||
{ | { | ||||
if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); | if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); | ||||
var dbTransaction = dbConnection.BeginTransaction(); | var dbTransaction = dbConnection.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<SqlServerCapTransaction>(publisher.ServiceProvider); | |||||
var capTransaction = publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | var capTransaction = publisher.Transaction.Value.Begin(dbTransaction, autoCommit); | ||||
return (IDbTransaction) capTransaction.DbTransaction; | |||||
return (IDbTransaction)capTransaction.DbTransaction; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -181,7 +180,7 @@ namespace DotNetCore.CAP | |||||
ICapPublisher publisher, bool autoCommit = false) | ICapPublisher publisher, bool autoCommit = false) | ||||
{ | { | ||||
var trans = database.BeginTransaction(); | var trans = database.BeginTransaction(); | ||||
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>(); | |||||
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<SqlServerCapTransaction>(publisher.ServiceProvider); | |||||
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); | ||||
return new CapEFDbTransaction(capTrans); | return new CapEFDbTransaction(capTrans); | ||||
} | } | ||||