发布x.6.0.1-preview预览版
This commit is contained in:
parent
9aca4866ce
commit
2db46f1e9a
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.5.0.14
|
||||
set EFCORE3=3.5.0.14
|
||||
set EFCORE5=5.5.0.14
|
||||
set EFCORE6=6.5.0.14
|
||||
set EFCORE2=2.6.0.1-preview0.0.1
|
||||
set EFCORE3=3.6.0.1-preview0.0.1
|
||||
set EFCORE5=5.6.0.1-preview0.0.1
|
||||
set EFCORE6=6.6.0.1-preview0.0.1
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Sample.MySql
|
|||
{
|
||||
builder.UseMySql(connection, new MySqlServerVersion(new Version())).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).UseLoggerFactory(efLogger);
|
||||
});
|
||||
o.AddDefaultDataSource("ds0","server=127.0.0.1;port=3306;database=dbdbd0;userid=root;password=root;");
|
||||
o.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=dbdbd0;userid=root;password=root;");
|
||||
})
|
||||
.Build(sp);
|
||||
stopwatch.Stop();
|
||||
|
@ -111,6 +111,7 @@ namespace Sample.MySql
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
app.ApplicationServices.UseAutoShardingCreate();
|
||||
app.ApplicationServices.UseAutoTryCompensateTable();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
|
|
@ -24,7 +24,7 @@ using ShardingCore.TableCreator;
|
|||
|
||||
namespace ShardingCore.Core.RuntimeContexts
|
||||
{
|
||||
public sealed class ShardingRuntimeContext:IShardingRuntimeContext
|
||||
public sealed class ShardingRuntimeContext : IShardingRuntimeContext
|
||||
{
|
||||
private bool isInited = false;
|
||||
private object INIT_LOCK = new object();
|
||||
|
@ -32,7 +32,7 @@ namespace ShardingCore.Core.RuntimeContexts
|
|||
private object INIT_MODEL = new object();
|
||||
private IServiceCollection _serviceMap = new ServiceCollection();
|
||||
|
||||
private IServiceProvider _serviceProvider;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private IServiceProvider _applicationServiceProvider;
|
||||
|
||||
public void AddServiceConfig(Action<IServiceCollection> configure)
|
||||
|
@ -53,6 +53,7 @@ namespace ShardingCore.Core.RuntimeContexts
|
|||
isInited = true;
|
||||
_serviceProvider = _serviceMap.BuildServiceProvider();
|
||||
_serviceProvider.GetRequiredService<IShardingInitializer>().Initialize();
|
||||
InitFieldValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,85 +62,101 @@ namespace ShardingCore.Core.RuntimeContexts
|
|||
GetRequiredService<IShardingBootstrapper>().AutoShardingCreate();
|
||||
}
|
||||
|
||||
private IShardingComparer _shardingComparer;
|
||||
public IShardingComparer GetShardingComparer()
|
||||
{
|
||||
return GetRequiredService<IShardingComparer>();
|
||||
return _shardingComparer??=GetRequiredService<IShardingComparer>();
|
||||
}
|
||||
|
||||
private IShardingCompilerExecutor _shardingCompilerExecutor;
|
||||
public IShardingCompilerExecutor GetShardingCompilerExecutor()
|
||||
{
|
||||
return GetRequiredService<IShardingCompilerExecutor>();
|
||||
return _shardingCompilerExecutor??=GetRequiredService<IShardingCompilerExecutor>();
|
||||
}
|
||||
|
||||
private IShardingReadWriteManager _shardingReadWriteManager;
|
||||
public IShardingReadWriteManager GetShardingReadWriteManager()
|
||||
{
|
||||
return GetRequiredService<IShardingReadWriteManager>();
|
||||
return _shardingReadWriteManager??=GetRequiredService<IShardingReadWriteManager>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ITrackerManager _trackerManager;
|
||||
public ITrackerManager GetTrackerManager()
|
||||
{
|
||||
return GetRequiredService<ITrackerManager>();
|
||||
return _trackerManager??=GetRequiredService<ITrackerManager>();
|
||||
}
|
||||
|
||||
private IParallelTableManager _parallelTableManager;
|
||||
public IParallelTableManager GetParallelTableManager()
|
||||
{
|
||||
return GetRequiredService<IParallelTableManager>();
|
||||
return _parallelTableManager??=GetRequiredService<IParallelTableManager>();
|
||||
}
|
||||
|
||||
private IDbContextCreator _dbContextCreator;
|
||||
public IDbContextCreator GetDbContextCreator()
|
||||
{
|
||||
return GetRequiredService<IDbContextCreator>();
|
||||
return _dbContextCreator??=GetRequiredService<IDbContextCreator>();
|
||||
}
|
||||
|
||||
private IEntityMetadataManager _entityMetadataManager;
|
||||
public IEntityMetadataManager GetEntityMetadataManager()
|
||||
{
|
||||
return GetRequiredService<IEntityMetadataManager>();
|
||||
return _entityMetadataManager??=GetRequiredService<IEntityMetadataManager>();
|
||||
}
|
||||
|
||||
private IVirtualDataSource _virtualDataSource;
|
||||
public IVirtualDataSource GetVirtualDataSource()
|
||||
{
|
||||
return GetRequiredService<IVirtualDataSource>();
|
||||
return _virtualDataSource??=GetRequiredService<IVirtualDataSource>();
|
||||
}
|
||||
|
||||
private ITableRouteManager _tableRouteManager;
|
||||
public ITableRouteManager GetTableRouteManager()
|
||||
{
|
||||
return GetRequiredService<ITableRouteManager>();
|
||||
return _tableRouteManager??=GetRequiredService<ITableRouteManager>();
|
||||
}
|
||||
|
||||
private IReadWriteConnectorFactory _readWriteConnectorFactory;
|
||||
public IReadWriteConnectorFactory GetReadWriteConnectorFactory()
|
||||
{
|
||||
return GetRequiredService<IReadWriteConnectorFactory>();
|
||||
return _readWriteConnectorFactory??=GetRequiredService<IReadWriteConnectorFactory>();
|
||||
}
|
||||
|
||||
private IShardingTableCreator _shardingTableCreator;
|
||||
public IShardingTableCreator GetShardingTableCreator()
|
||||
{
|
||||
return GetRequiredService<IShardingTableCreator>();
|
||||
return _shardingTableCreator??=GetRequiredService<IShardingTableCreator>();
|
||||
}
|
||||
|
||||
private IRouteTailFactory _routeTailFactory;
|
||||
public IRouteTailFactory GetRouteTailFactory()
|
||||
{
|
||||
return GetRequiredService<IRouteTailFactory>();
|
||||
return _routeTailFactory??=GetRequiredService<IRouteTailFactory>();
|
||||
}
|
||||
|
||||
private IQueryTracker _queryTracker;
|
||||
public IQueryTracker GetQueryTracker()
|
||||
{
|
||||
return GetRequiredService<IQueryTracker>();
|
||||
return _queryTracker??=GetRequiredService<IQueryTracker>();
|
||||
}
|
||||
|
||||
private IUnionAllMergeManager _unionAllMergeManager;
|
||||
public IUnionAllMergeManager GetUnionAllMergeManager()
|
||||
{
|
||||
return GetRequiredService<IUnionAllMergeManager>();
|
||||
return _unionAllMergeManager??=GetRequiredService<IUnionAllMergeManager>();
|
||||
}
|
||||
|
||||
private IShardingPageManager _shardingPageManager;
|
||||
public IShardingPageManager GetShardingPageManager()
|
||||
{
|
||||
return GetRequiredService<IShardingPageManager>();
|
||||
return _shardingPageManager??=GetRequiredService<IShardingPageManager>();
|
||||
}
|
||||
|
||||
private IDataSourceInitializer _dataSourceInitializer;
|
||||
public IDataSourceInitializer GetDataSourceInitializer()
|
||||
{
|
||||
return GetRequiredService<IDataSourceInitializer>();
|
||||
return _dataSourceInitializer??=GetRequiredService<IDataSourceInitializer>();
|
||||
}
|
||||
|
||||
public void GetOrCreateShardingRuntimeModel(DbContext dbContext)
|
||||
|
@ -147,12 +164,14 @@ namespace ShardingCore.Core.RuntimeContexts
|
|||
if (isInitModeled) return;
|
||||
lock (INIT_MODEL)
|
||||
{
|
||||
if(isInitModeled) return;
|
||||
if (isInitModeled) return;
|
||||
isInitModeled = true;
|
||||
var entityMetadataManager = GetService<IEntityMetadataManager>();
|
||||
var trackerManager = GetService<ITrackerManager>();
|
||||
var entityTypes = dbContext.Model.GetEntityTypes();
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
trackerManager.AddDbContextModel(entityType.ClrType, entityType.FindPrimaryKey() != null);
|
||||
entityMetadataManager.TryInitModel(entityType);
|
||||
}
|
||||
}
|
||||
|
@ -178,43 +197,66 @@ namespace ShardingCore.Core.RuntimeContexts
|
|||
if (!isInited)
|
||||
throw new InvalidOperationException("sharding runtime not init");
|
||||
}
|
||||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetService(serviceType);
|
||||
}
|
||||
|
||||
public TService GetService<TService>()
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetService<TService>();
|
||||
}
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetService(serviceType);
|
||||
}
|
||||
|
||||
public object GetRequiredService(Type serviceType)
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetRequiredService(serviceType);
|
||||
}
|
||||
public TService GetService<TService>()
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetService<TService>();
|
||||
}
|
||||
|
||||
public TService GetRequiredService<TService>()
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetRequiredService<TService>();
|
||||
}
|
||||
public IShardingRouteManager GetShardingRouteManager()
|
||||
{
|
||||
return GetRequiredService<IShardingRouteManager>();
|
||||
}
|
||||
//
|
||||
// public IShardingRouteConfigOptions<TShardingDbContext> GetRequiredShardingEntityConfigOption<TShardingDbContext>()
|
||||
// where TShardingDbContext : DbContext, IShardingDbContext
|
||||
// {
|
||||
// return (IShardingRouteConfigOptions<TShardingDbContext>)GetRequiredShardingEntityConfigOption(typeof(TShardingDbContext));
|
||||
// }
|
||||
// public IShardingRouteConfigOptions GetRequiredShardingEntityConfigOption(Type shardingDbContextType)
|
||||
// {
|
||||
// return (IShardingRouteConfigOptions)GetService(typeof(IShardingRouteConfigOptions<>).GetGenericType0(shardingDbContextType));
|
||||
// }
|
||||
public object GetRequiredService(Type serviceType)
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetRequiredService(serviceType);
|
||||
}
|
||||
|
||||
public TService GetRequiredService<TService>()
|
||||
{
|
||||
CheckIfNotBuild();
|
||||
return _serviceProvider.GetRequiredService<TService>();
|
||||
}
|
||||
public IShardingRouteManager GetShardingRouteManager()
|
||||
{
|
||||
return GetRequiredService<IShardingRouteManager>();
|
||||
}
|
||||
//
|
||||
// public IShardingRouteConfigOptions<TShardingDbContext> GetRequiredShardingEntityConfigOption<TShardingDbContext>()
|
||||
// where TShardingDbContext : DbContext, IShardingDbContext
|
||||
// {
|
||||
// return (IShardingRouteConfigOptions<TShardingDbContext>)GetRequiredShardingEntityConfigOption(typeof(TShardingDbContext));
|
||||
// }
|
||||
// public IShardingRouteConfigOptions GetRequiredShardingEntityConfigOption(Type shardingDbContextType)
|
||||
// {
|
||||
// return (IShardingRouteConfigOptions)GetService(typeof(IShardingRouteConfigOptions<>).GetGenericType0(shardingDbContextType));
|
||||
// }
|
||||
|
||||
|
||||
private void InitFieldValue()
|
||||
{
|
||||
|
||||
GetShardingComparer();
|
||||
GetShardingCompilerExecutor();
|
||||
GetShardingReadWriteManager();
|
||||
GetShardingRouteManager();
|
||||
GetTrackerManager();
|
||||
GetParallelTableManager();
|
||||
GetDbContextCreator();
|
||||
GetEntityMetadataManager();
|
||||
GetVirtualDataSource();
|
||||
GetTableRouteManager();
|
||||
GetShardingTableCreator();
|
||||
GetRouteTailFactory();
|
||||
GetReadWriteConnectorFactory();
|
||||
GetQueryTracker();
|
||||
GetUnionAllMergeManager();
|
||||
GetShardingPageManager();
|
||||
GetDataSourceInitializer();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
|
|||
{
|
||||
if (!_doOnlyOnce.IsUnDo())
|
||||
throw new ShardingCoreInvalidOperationException("already init");
|
||||
RouteShardingProvider = shardingProvider;
|
||||
EntityMetadata = entityMetadata;
|
||||
|
||||
// RouteConfigOptions = shardingProvider.GetService<IShardingRouteConfigOptions>();
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace ShardingCore.EFCores
|
|||
public ShardingInternalDbSet(DbContext context) : base(context)
|
||||
{
|
||||
_context = (IShardingDbContext)context;
|
||||
_shardingRuntimeContext = context.GetService<IShardingRuntimeContext>();
|
||||
}
|
||||
#endif
|
||||
private IVirtualDataSource _virtualDataSource;
|
||||
|
|
|
@ -90,15 +90,6 @@ namespace ShardingCore
|
|||
public static void UseDefaultSharding<TShardingDbContext>(IServiceProvider serviceProvider,DbContextOptionsBuilder dbContextOptionsBuilder) where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
var shardingRuntimeContext = serviceProvider.GetRequiredService<IShardingRuntimeContext>();
|
||||
// Stopwatch sp=Stopwatch.StartNew();
|
||||
// for (int i = 0; i < 100000; i++)
|
||||
// {
|
||||
//
|
||||
// var virtualDataSource1 = shardingRuntimeContext.GetVirtualDataSource();
|
||||
//
|
||||
// }
|
||||
// sp.Stop();
|
||||
// Console.WriteLine(sp.ElapsedMilliseconds);
|
||||
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||
var connectionString = virtualDataSource.GetConnectionString(virtualDataSource.DefaultDataSourceName);
|
||||
var contextOptionsBuilder = virtualDataSource.ConfigurationParams.UseDbContextOptionsBuilder(connectionString, dbContextOptionsBuilder)
|
||||
|
|
|
@ -8,7 +8,7 @@ using Xunit;
|
|||
|
||||
namespace ShardingCore.CommonTest
|
||||
{
|
||||
|
||||
|
||||
public class ShardingTableTime
|
||||
{
|
||||
private readonly EntityMetadata _testEntityMetadata;
|
||||
|
|
|
@ -95,8 +95,8 @@ namespace ShardingCore.Test
|
|||
// 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法
|
||||
public void Configure(IServiceProvider serviceProvider)
|
||||
{
|
||||
var shardingBootstrapper = serviceProvider.GetRequiredService<IShardingBootstrapper>();
|
||||
shardingBootstrapper.AutoShardingCreate();
|
||||
serviceProvider.UseAutoShardingCreate();
|
||||
serviceProvider.UseAutoTryCompensateTable();
|
||||
// 有一些测试数据要初始化可以放在这里
|
||||
InitData(serviceProvider).GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace ShardingCore.Test2x.Shardings
|
|||
}
|
||||
public override void Configure(EntityMetadataTableBuilder<Order> builder)
|
||||
{
|
||||
|
||||
builder.ShardingProperty(o => o.CreateTime);
|
||||
}
|
||||
|
||||
public override IPaginationConfiguration<Order> CreatePaginationConfiguration()
|
||||
|
|
|
@ -107,8 +107,8 @@ namespace ShardingCore.Test2x
|
|||
// 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法
|
||||
public void Configure(IServiceProvider serviceProvider)
|
||||
{
|
||||
var shardingBootstrapper = serviceProvider.GetRequiredService<IShardingBootstrapper>();
|
||||
shardingBootstrapper.AutoShardingCreate();
|
||||
serviceProvider.UseAutoShardingCreate();
|
||||
serviceProvider.UseAutoTryCompensateTable();
|
||||
// 有一些测试数据要初始化可以放在这里
|
||||
InitData(serviceProvider).GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
|
@ -94,8 +94,8 @@ namespace ShardingCore.Test3x
|
|||
// 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法
|
||||
public void Configure(IServiceProvider serviceProvider)
|
||||
{
|
||||
var shardingBootstrapper = serviceProvider.GetService<IShardingBootstrapper>();
|
||||
shardingBootstrapper.AutoShardingCreate();
|
||||
serviceProvider.UseAutoShardingCreate();
|
||||
serviceProvider.UseAutoTryCompensateTable();
|
||||
// 有一些测试数据要初始化可以放在这里
|
||||
InitData(serviceProvider).GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue