Commit 3562973c authored by hjqcan's avatar hjqcan Committed by Savorboard

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
parent d0d8b40d
...@@ -31,9 +31,13 @@ namespace DotNetCore.CAP ...@@ -31,9 +31,13 @@ namespace DotNetCore.CAP
{ {
services.AddSingleton(x => services.AddSingleton(x =>
{ {
var dbContext = (DbContext)x.GetService(mysqlOptions.DbContextType); using (var scope = x.CreateScope())
mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; {
return mysqlOptions; var provider = scope.ServiceProvider;
var dbContext = (DbContext)provider.GetService(mysqlOptions.DbContextType);
mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
return mysqlOptions;
}
}); });
} }
else else
......
...@@ -31,9 +31,13 @@ namespace DotNetCore.CAP ...@@ -31,9 +31,13 @@ namespace DotNetCore.CAP
{ {
services.AddSingleton(x => services.AddSingleton(x =>
{ {
var dbContext = (DbContext)x.GetService(postgreSqlOptions.DbContextType); using (var scope = x.CreateScope())
postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; {
return postgreSqlOptions; var provider = scope.ServiceProvider;
var dbContext = (DbContext)provider.GetService(postgreSqlOptions.DbContextType);
postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
return postgreSqlOptions;
}
}); });
} }
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment