diff --git a/src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs b/src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs index 1d4630857..ff9d24b20 100644 --- a/src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs @@ -25,9 +25,7 @@ public void AddServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - - services.AddTransient(); + services.AddSingleton(); services.Configure(_configure); diff --git a/src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs b/src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs index 4688e4ff7..11c1b2706 100644 --- a/src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs +++ b/src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs @@ -81,7 +81,7 @@ public static IClientSessionHandle StartTransaction(this IMongoClient client, ICapPublisher publisher, bool autoCommit = false) { var clientSessionHandle = client.StartSession(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); var capTrans = publisher.Transaction.Value.Begin(clientSessionHandle, autoCommit); return new CapMongoDbClientSessionHandle(capTrans); } diff --git a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs index 3c13983ee..f9776da6d 100644 --- a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs @@ -26,7 +26,6 @@ public void AddServices(IServiceCollection services) services.AddSingleton(); services.TryAddSingleton(); - services.AddTransient(); //Add MySqlOptions services.Configure(_configure); diff --git a/src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs b/src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs index b87c3ee5f..61fd2dea1 100644 --- a/src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs +++ b/src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs @@ -121,7 +121,7 @@ public static IDbContextTransaction BeginTransaction(this DatabaseFacade databas ICapPublisher publisher, bool autoCommit = false) { var trans = database.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); return new CapEFDbTransaction(capTrans); } @@ -142,7 +142,7 @@ public static ICapTransaction BeginTransaction(this IDbConnection dbConnection, } var dbTransaction = dbConnection.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); } } diff --git a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs index fbc23c132..34cbdd258 100644 --- a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs @@ -27,7 +27,6 @@ public void AddServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs b/src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs index 037b25d15..97a9aba48 100644 --- a/src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs +++ b/src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs @@ -124,7 +124,7 @@ public static ICapTransaction BeginTransaction(this IDbConnection dbConnection, if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); var dbTransaction = dbConnection.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); return publisher.Transaction.Value.Begin(dbTransaction, autoCommit); } @@ -139,7 +139,7 @@ public static IDbContextTransaction BeginTransaction(this DatabaseFacade databas ICapPublisher publisher, bool autoCommit = false) { var trans = database.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); return new CapEFDbTransaction(capTrans); } diff --git a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs index e543be021..93428b9b3 100644 --- a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs @@ -29,7 +29,6 @@ public void AddServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.Configure(_configure); diff --git a/src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs b/src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs index b13787cea..eba585ffd 100644 --- a/src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs +++ b/src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs @@ -46,14 +46,14 @@ protected override void AddToSent(MediumMessage msg) 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)) { list.Add(msg); } else { - var msgList = new List(1) {msg}; + var msgList = new List(1) { msg }; _diagnosticProcessor.BufferList.TryAdd(transactionKey, msgList); } } @@ -163,11 +163,10 @@ public static IDbTransaction BeginTransaction(this IDbConnection dbConnection, ICapPublisher publisher, bool autoCommit = false) { if (dbConnection.State == ConnectionState.Closed) dbConnection.Open(); - var dbTransaction = dbConnection.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); var capTransaction = publisher.Transaction.Value.Begin(dbTransaction, autoCommit); - return (IDbTransaction) capTransaction.DbTransaction; + return (IDbTransaction)capTransaction.DbTransaction; } /// @@ -181,7 +180,7 @@ public static IDbContextTransaction BeginTransaction(this DatabaseFacade databas ICapPublisher publisher, bool autoCommit = false) { var trans = database.BeginTransaction(); - publisher.Transaction.Value = publisher.ServiceProvider.GetService(); + publisher.Transaction.Value = ActivatorUtilities.CreateInstance(publisher.ServiceProvider); var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit); return new CapEFDbTransaction(capTrans); }