Commit 9ef8d4c4 authored by yangxiaodong's avatar yangxiaodong

fix issue #16.

parent e62c8ff5
...@@ -26,14 +26,13 @@ namespace DotNetCore.CAP ...@@ -26,14 +26,13 @@ namespace DotNetCore.CAP
var sqlServerOptions = new MySqlOptions(); var sqlServerOptions = new MySqlOptions();
_configure(sqlServerOptions); _configure(sqlServerOptions);
var provider = TempBuildService(services); if (sqlServerOptions.DbContextType != null)
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType);
if (dbContextObj != 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 ...@@ -26,14 +26,13 @@ namespace DotNetCore.CAP
var sqlServerOptions = new SqlServerOptions(); var sqlServerOptions = new SqlServerOptions();
_configure(sqlServerOptions); _configure(sqlServerOptions);
var provider = TempBuildService(services); if (sqlServerOptions.DbContextType != null)
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType);
if (dbContextObj != 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);
} }
......
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