This commit is contained in:
parent
cc2d7e72b1
commit
c4931470fe
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
|
||||
namespace ShardingCore.Core
|
||||
{
|
||||
|
||||
public interface IShardingRuntimeContext
|
||||
{
|
||||
object GetService(Type serviceType);
|
||||
TService GetService<TService>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace ShardingCore.Core
|
||||
{
|
||||
public interface IShardingRuntimeContextFactory
|
||||
{
|
||||
IShardingRuntimeContext Create();
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShardingCore.Core;
|
||||
|
||||
namespace ShardingCore.EFCores.OptionsExtensions
|
||||
{
|
||||
|
@ -17,12 +18,16 @@ namespace ShardingCore.EFCores.OptionsExtensions
|
|||
#if EFCORE6
|
||||
public class ShardingWrapOptionsExtension : IDbContextOptionsExtension
|
||||
{
|
||||
public ShardingWrapOptionsExtension()
|
||||
private readonly IShardingRuntimeContext _shardingRuntimeContext;
|
||||
|
||||
public ShardingWrapOptionsExtension(IShardingRuntimeContext shardingRuntimeContext)
|
||||
{
|
||||
_shardingRuntimeContext = shardingRuntimeContext;
|
||||
Console.WriteLine("ShardingWrapOptionsExtension ctor");
|
||||
}
|
||||
public void ApplyServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IShardingRuntimeContext>(sp => _shardingRuntimeContext);
|
||||
Console.WriteLine("ShardingWrapOptionsExtension ApplyServices");
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ namespace ShardingCore.EFCores
|
|||
private readonly IShardingDbContext _shardingDbContext;
|
||||
private readonly IShardingCompilerExecutor _shardingCompilerExecutor;
|
||||
|
||||
public ShardingQueryCompiler(ICurrentDbContext currentContext)
|
||||
public ShardingQueryCompiler(ICurrentDbContext currentContext,IShardingRuntimeContext shardingRuntimeContext)
|
||||
{
|
||||
_shardingDbContext = currentContext.Context as IShardingDbContext ??
|
||||
throw new ShardingCoreException("db context operator is not IShardingDbContext");
|
||||
_shardingCompilerExecutor = ShardingRuntimeContext.GetInstance().GetService<IShardingCompilerExecutor>();
|
||||
_shardingCompilerExecutor = shardingRuntimeContext.GetService<IShardingCompilerExecutor>();
|
||||
}
|
||||
|
||||
public TResult Execute<TResult>(Expression query)
|
||||
|
|
Loading…
Reference in New Issue