Skip to content

Commit

Permalink
Fixed asp.net core 2.0 startup error about issue #44 of MySql and Pos…
Browse files Browse the repository at this point in the history
…tgreSql (#51)

Fixed asp.net core 2.0 startup error about issue #44 of MySql and PostgreSql
  • Loading branch information
hjqcan authored and yang-xiaodong committed Sep 29, 2017
1 parent d0d8b40 commit 3562973
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public void AddServices(IServiceCollection services)
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public void AddServices(IServiceCollection services)
{
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
Expand Down

0 comments on commit 3562973

Please sign in to comment.