@@ -26,14 +26,13 @@ namespace DotNetCore.CAP | |||||
var sqlServerOptions = new MySqlOptions(); | var sqlServerOptions = new MySqlOptions(); | ||||
_configure(sqlServerOptions); | _configure(sqlServerOptions); | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType); | |||||
if (dbContextObj != null) | |||||
if (sqlServerOptions.DbContextType != null) | |||||
{ | { | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType); | |||||
var dbContext = (DbContext)dbContextObj; | var dbContext = (DbContext)dbContextObj; | ||||
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | ||||
} | } | ||||
services.Configure(_configure); | |||||
services.AddSingleton(sqlServerOptions); | services.AddSingleton(sqlServerOptions); | ||||
} | } | ||||
@@ -26,14 +26,13 @@ namespace DotNetCore.CAP | |||||
var sqlServerOptions = new SqlServerOptions(); | var sqlServerOptions = new SqlServerOptions(); | ||||
_configure(sqlServerOptions); | _configure(sqlServerOptions); | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType); | |||||
if (dbContextObj != null) | |||||
if (sqlServerOptions.DbContextType != null) | |||||
{ | { | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType); | |||||
var dbContext = (DbContext)dbContextObj; | var dbContext = (DbContext)dbContextObj; | ||||
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | ||||
} | } | ||||
services.Configure(_configure); | |||||
services.AddSingleton(sqlServerOptions); | services.AddSingleton(sqlServerOptions); | ||||
} | } | ||||