yangxiaodong преди 7 години
родител
ревизия
9740e5353d
променени са 1 файла, в които са добавени 11 реда и са изтрити 18 реда
  1. +11
    -18
      src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs

+ 11
- 18
src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs Целия файл

@@ -24,29 +24,22 @@ namespace DotNetCore.CAP
services.AddTransient<IAdditionalProcessor, DefaultAdditionalProcessor>();

var sqlServerOptions = new SqlServerOptions();

_configure(sqlServerOptions);

if (sqlServerOptions.DbContextType != null)
{
var provider = TempBuildService(services);
var dbContextObj = provider.GetService(sqlServerOptions.DbContextType);
var dbContext = (DbContext)dbContextObj;
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
services.AddSingleton(x =>
{
var dbContext = (DbContext)x.GetService(sqlServerOptions.DbContextType);
sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
return sqlServerOptions;
});
}
else
{
services.AddSingleton(sqlServerOptions);
}
services.AddSingleton(sqlServerOptions);
}

#if NETSTANDARD1_6
private IServiceProvider TempBuildService(IServiceCollection services)
{
return services.BuildServiceProvider();
}
#else
private ServiceProvider TempBuildService(IServiceCollection services)
{
return services.BuildServiceProvider();
}
#endif

}
}

Зареждане…
Отказ
Запис