publish x.2.0.16
This commit is contained in:
parent
032eccc575
commit
fba46257a5
|
@ -1,8 +1,8 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.2.0.15
|
||||
set EFCORE3=3.2.0.15
|
||||
set EFCORE5=5.2.0.15
|
||||
set EFCORE2=2.2.0.16
|
||||
set EFCORE3=3.2.0.16
|
||||
set EFCORE5=5.2.0.16
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
namespace ShardingCore.Core.ShardingAccessors.Abstractions
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Tuesday, 22 December 2020 15:13:44
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public interface IShardingAccessor
|
||||
{
|
||||
ShardingContext ShardingContext { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
namespace ShardingCore.Core.ShardingAccessors
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Wednesday, 23 December 2020 07:51:00
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
/// <summary>
|
||||
/// 查询scope创建
|
||||
/// </summary>
|
||||
public interface IShardingScopeFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建查询scope
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ShardingScope CreateScope();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
using System.Threading;
|
||||
using ShardingCore.Core.ShardingAccessors.Abstractions;
|
||||
using ShardingCore.Core.VirtualTables;
|
||||
|
||||
namespace ShardingCore.Core.ShardingAccessors
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Tuesday, 22 December 2020 15:14:15
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
/// <summary>
|
||||
/// 分表访问器
|
||||
/// </summary>
|
||||
public class ShardingAccessor : IShardingAccessor
|
||||
{
|
||||
private static AsyncLocal<ShardingContext> _shardingContext = new AsyncLocal<ShardingContext>();
|
||||
|
||||
/// <summary>
|
||||
/// 分表访问器
|
||||
/// </summary>
|
||||
public ShardingAccessor(IVirtualTableManager virtualTableManager)
|
||||
{
|
||||
VirtualTableManager = virtualTableManager;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ShardingContext ShardingContext
|
||||
{
|
||||
get => _shardingContext.Value;
|
||||
set => _shardingContext.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟表管理者
|
||||
/// </summary>
|
||||
public IVirtualTableManager VirtualTableManager { get; }
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
|
||||
using ShardingCore.Core.VirtualTables;
|
||||
using ShardingCore.Extensions;
|
||||
|
||||
namespace ShardingCore.Core.ShardingAccessors
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Tuesday, 22 December 2020 15:04:47
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingContext
|
||||
{
|
||||
private ShardingContext(RouteResult routeResult)
|
||||
{
|
||||
foreach (var physicTable in routeResult.ReplaceTables)
|
||||
{
|
||||
_shardingTables.Add(physicTable.EntityType, physicTable.Tail);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分表操作上下文 key:物理表名 value:虚拟表和本次分表tails
|
||||
/// </summary>
|
||||
private readonly Dictionary<Type, string> _shardingTables = new Dictionary<Type, string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个分表上下文
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ShardingContext Create(RouteResult routeResult)
|
||||
{
|
||||
return new ShardingContext(routeResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分表信息
|
||||
/// </summary>
|
||||
/// <param name="entityType"></param>
|
||||
/// <returns></returns>
|
||||
public string GetContextQueryTail(Type entityType)
|
||||
{
|
||||
if (_shardingTables.ContainsKey(entityType))
|
||||
return _shardingTables[entityType];
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否是空的
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _shardingTables.IsEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using ShardingCore.Core.ShardingAccessors.Abstractions;
|
||||
|
||||
namespace ShardingCore.Core.ShardingAccessors
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Wednesday, 23 December 2020 07:51:30
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingScope : IDisposable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 分表配置访问器
|
||||
/// </summary>
|
||||
public IShardingAccessor ShardingAccessor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="shardingAccessor"></param>
|
||||
public ShardingScope(IShardingAccessor shardingAccessor)
|
||||
{
|
||||
shardingAccessor.ShardingContext = null;
|
||||
ShardingAccessor = shardingAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
ShardingAccessor.ShardingContext = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
using ShardingCore.Core.ShardingAccessors.Abstractions;
|
||||
|
||||
namespace ShardingCore.Core.ShardingAccessors
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Wednesday, 23 December 2020 08:11:06
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
/// <summary>
|
||||
/// 分表查询环境创建
|
||||
/// </summary>
|
||||
public class ShardingScopeFactory : IShardingScopeFactory
|
||||
{
|
||||
private readonly IShardingAccessor _shardingAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="shardingAccessor"></param>
|
||||
public ShardingScopeFactory(IShardingAccessor shardingAccessor)
|
||||
{
|
||||
_shardingAccessor = shardingAccessor;
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建scope
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ShardingScope CreateScope()
|
||||
{
|
||||
return new ShardingScope(_shardingAccessor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,8 +14,6 @@ using ShardingCore.TableCreator;
|
|||
using System;
|
||||
using ShardingCore.Core.QueryRouteManagers;
|
||||
using ShardingCore.Core.QueryRouteManagers.Abstractions;
|
||||
using ShardingCore.Core.ShardingAccessors;
|
||||
using ShardingCore.Core.ShardingAccessors.Abstractions;
|
||||
using ShardingCore.Core.ShardingPage;
|
||||
using ShardingCore.Core.ShardingPage.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes;
|
||||
|
@ -69,7 +67,43 @@ namespace ShardingCore
|
|||
|
||||
|
||||
|
||||
services.AddSingleton<IShardingBootstrapper, ShardingBootstrapper>();
|
||||
return services;
|
||||
}
|
||||
public static IServiceCollection AddShardingDbContext<TShardingDbContext, TActualDbContext>(this IServiceCollection services,
|
||||
Action<IServiceProvider,DbContextOptionsBuilder> optionsAction = null,
|
||||
Action<ShardingConfigOption<TShardingDbContext,TActualDbContext>> configure=null,
|
||||
ServiceLifetime contextLifetime = ServiceLifetime.Scoped,
|
||||
ServiceLifetime optionsLifetime = ServiceLifetime.Scoped)
|
||||
where TActualDbContext : DbContext, IShardingTableDbContext
|
||||
where TShardingDbContext : DbContext, IShardingTableDbContext<TActualDbContext>
|
||||
{
|
||||
if (configure == null)
|
||||
throw new ArgumentNullException($"AddShardingDbContext params is null :{nameof(configure)}");
|
||||
|
||||
ShardingCoreHelper.CheckContextConstructors<TActualDbContext>();
|
||||
var shardingConfigOptions = new ShardingConfigOption<TShardingDbContext,TActualDbContext>();
|
||||
configure?.Invoke(shardingConfigOptions);
|
||||
services.AddSingleton<IShardingConfigOption, ShardingConfigOption<TShardingDbContext, TActualDbContext>>(sp=> shardingConfigOptions);
|
||||
|
||||
|
||||
//添加创建TActualDbContext 的 创建者
|
||||
var config = new ShardingDbContextOptionsBuilderConfig<TShardingDbContext>(shardingConfigOptions.SameConnectionConfigure,shardingConfigOptions.DefaultQueryConfigure);
|
||||
services.AddSingleton<IShardingDbContextOptionsBuilderConfig, ShardingDbContextOptionsBuilderConfig<TShardingDbContext>>(sp=> config);
|
||||
|
||||
//添加创建TActualDbContext创建者
|
||||
services.AddSingleton<IShardingDbContextCreatorConfig,DefaultShardingDbContextCreatorConfig<TShardingDbContext, TActualDbContext>>(sp=> new DefaultShardingDbContextCreatorConfig<TShardingDbContext, TActualDbContext>(typeof(TActualDbContext)));
|
||||
|
||||
|
||||
Action<IServiceProvider, DbContextOptionsBuilder> shardingOptionAction = (sp, option) =>
|
||||
{
|
||||
optionsAction?.Invoke(sp,option);
|
||||
option.UseSharding();
|
||||
};
|
||||
services.AddDbContext<TShardingDbContext>(shardingOptionAction, contextLifetime, optionsLifetime);
|
||||
services.AddInternalShardingCore();
|
||||
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
@ -85,9 +119,6 @@ namespace ShardingCore
|
|||
services.AddSingleton<IRoutingRuleEngineFactory, RoutingRuleEngineFactory>();
|
||||
//分表引擎
|
||||
services.AddSingleton<IRouteRuleEngine, QueryRouteRuleEngines>();
|
||||
//services.AddSingleton(typeof(IVirtualTable<>), typeof(OneDbVirtualTable<>));
|
||||
services.AddSingleton<IShardingAccessor, ShardingAccessor>();
|
||||
services.AddSingleton<IShardingScopeFactory, ShardingScopeFactory>();
|
||||
services.AddSingleton<IRouteTailFactory, RouteTailFactory>();
|
||||
services.AddSingleton<IShardingQueryExecutor, DefaultShardingQueryExecutor>();
|
||||
|
||||
|
@ -98,6 +129,7 @@ namespace ShardingCore
|
|||
//sharding page
|
||||
services.AddSingleton<IShardingPageManager, ShardingPageManager>();
|
||||
services.AddSingleton<IShardingPageAccessor, ShardingPageAccessor>();
|
||||
services.AddSingleton<IShardingBootstrapper, ShardingBootstrapper>();
|
||||
return services;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ using System.Text;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShardingCore.Core.ShardingAccessors.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Core.VirtualTables;
|
||||
using ShardingCore.DbContexts.ShardingDbContexts;
|
||||
|
|
|
@ -43,15 +43,15 @@ namespace ShardingCore.Sharding.PaginationConfigurations
|
|||
_metadata.ReverseTotalGe = reverseTotalGe;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 配置当分表数目小于多少后直接取到内存不在流式处理
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public PaginationBuilder<TEntity> ConfigTakeInMemoryCountIfLe(int count)
|
||||
{
|
||||
_metadata.TakeInMemoryCountIfLe = count;
|
||||
return this;
|
||||
}
|
||||
///// <summary>
|
||||
///// 配置当分表数目小于多少后直接取到内存不在流式处理
|
||||
///// </summary>
|
||||
///// <param name="count"></param>
|
||||
///// <returns></returns>
|
||||
//public PaginationBuilder<TEntity> ConfigTakeInMemoryCountIfLe(int count)
|
||||
//{
|
||||
// _metadata.TakeInMemoryCountIfLe = count;
|
||||
// return this;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using System.Linq;
|
||||
using ShardingCore.Core.ShardingAccessors;
|
||||
using ShardingCore.Core.VirtualRoutes.RouteTails.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding
|
||||
|
|
Loading…
Reference in New Issue