优化无iserviceprovider的初始化

This commit is contained in:
xuejiaming 2022-07-07 06:29:22 +08:00
parent b5aa66f37a
commit eab96611fa
1 changed files with 4 additions and 0 deletions

View File

@ -103,6 +103,10 @@ namespace ShardingCore
DbContextOptionsBuilder dbContextOptionsBuilder) where TShardingDbContext : DbContext, IShardingDbContext
{
var shardingRuntimeContext = serviceProvider.GetRequiredService<IShardingRuntimeContext>();
dbContextOptionsBuilder.UseDefaultSharding<TShardingDbContext>(shardingRuntimeContext);
}
public static void UseDefaultSharding<TShardingDbContext>(this DbContextOptionsBuilder dbContextOptionsBuilder,IShardingRuntimeContext shardingRuntimeContext) where TShardingDbContext : DbContext, IShardingDbContext
{
var shardingConfigOptions = shardingRuntimeContext.GetShardingConfigOptions();
shardingConfigOptions.ShardingMigrationConfigure?.Invoke(dbContextOptionsBuilder);
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();