From 3562973ceb76fcdd7b5dbf3053f769471e57d9bf Mon Sep 17 00:00:00 2001 From: hjqcan Date: Fri, 29 Sep 2017 09:52:07 +0800 Subject: [PATCH 1/2] Fixed asp.net core 2.0 startup error about issue #44 of MySql and PostgreSql (#51) Fixed asp.net core 2.0 startup error about issue #44 of MySql and PostgreSql --- .../CAP.MySqlCapOptionsExtension.cs | 10 +++++++--- .../CAP.PostgreSqlCapOptionsExtension.cs | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs index b9c1b0d..ffe2cab 100644 --- a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs @@ -31,9 +31,13 @@ namespace DotNetCore.CAP { services.AddSingleton(x => { - var dbContext = (DbContext)x.GetService(mysqlOptions.DbContextType); - mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; - return mysqlOptions; + using (var scope = x.CreateScope()) + { + var provider = scope.ServiceProvider; + var dbContext = (DbContext)provider.GetService(mysqlOptions.DbContextType); + mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; + return mysqlOptions; + } }); } else diff --git a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs index e4381e0..29e5311 100644 --- a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs @@ -31,9 +31,13 @@ namespace DotNetCore.CAP { services.AddSingleton(x => { - var dbContext = (DbContext)x.GetService(postgreSqlOptions.DbContextType); - postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; - return postgreSqlOptions; + using (var scope = x.CreateScope()) + { + var provider = scope.ServiceProvider; + var dbContext = (DbContext)provider.GetService(postgreSqlOptions.DbContextType); + postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; + return postgreSqlOptions; + } }); } else From 8744532f8bb00de5b6d2d205bb150195e70dde56 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Fri, 29 Sep 2017 09:57:04 +0800 Subject: [PATCH 2/2] release 2.0.2 about PR #51 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 6c03b29..accac21 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 0 - 1 + 2 $(VersionMajor).$(VersionMinor).$(VersionPatch)