Kaynağa Gözat

refactor of DI.

master
yangxiaodong 7 yıl önce
ebeveyn
işleme
9740e5353d
1 değiştirilmiş dosya ile 11 ekleme ve 18 silme
  1. +11
    -18
      src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs

+ 11
- 18
src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs Dosyayı Görüntüle

@@ -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

}
}

Yükleniyor…
İptal
Kaydet