优化启动配置
This commit is contained in:
parent
20c758e248
commit
691fbab8a3
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.4.0.01-preview3
|
||||
set EFCORE3=3.4.0.01-preview3
|
||||
set EFCORE5=5.4.0.01-preview3
|
||||
set EFCORE6=6.4.0.01-preview3
|
||||
set EFCORE2=2.4.0.01-preview4
|
||||
set EFCORE3=3.4.0.01-preview4
|
||||
set EFCORE5=5.4.0.01-preview4
|
||||
set EFCORE6=6.4.0.01-preview4
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -3,8 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.EntityShardingMetadatas;
|
||||
using ShardingCore.Core.TrackerManagers;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualTables;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
|
@ -16,13 +16,9 @@ using ShardingCore.Jobs;
|
|||
using ShardingCore.Jobs.Abstaractions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
|
||||
/*
|
||||
* @Author: xjm
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Core.ShardingConfigurations.Abstractions
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace ShardingCore.Core.ShardingConfigurations.Abstractions
|
||||
{
|
||||
public interface IShardingEntityConfigOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 如果数据库不存在就创建并且创建表除了分表的
|
||||
/// </summary>
|
||||
bool EnsureCreatedWithOutShardingTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要在启动时创建分表
|
||||
/// </summary>
|
||||
bool? CreateShardingTableOnStart { get; set; }
|
||||
/// <summary>
|
||||
/// 当查询遇到没有路由被命中时是否抛出错误
|
||||
/// </summary>
|
||||
bool ThrowIfQueryRouteNotMatch { get; set; }
|
||||
/// <summary>
|
||||
/// 忽略建表时的错误
|
||||
/// </summary>
|
||||
bool? IgnoreCreateTableError { get; set; }
|
||||
/// <summary>
|
||||
/// 是否启用分表路由编译缓存(默认只缓存单个操作的也就是<![CDATA[=,>,>=,<,<=]]>)
|
||||
/// default cache single filter route expression, <![CDATA[=,>,>=,<,<=]]> with sharding property
|
||||
/// </summary>
|
||||
bool? EnableTableRouteCompileCache { get; set; }
|
||||
/// <summary>
|
||||
/// 是否启用分库路由编译缓存(默认只缓存单个操作的也就是<![CDATA[=,>,>=,<,<=]]>)
|
||||
/// default cache single filter route expression, <![CDATA[=,>,>=,<,<=]]> with sharding property
|
||||
/// </summary>
|
||||
bool? EnableDataSourceRouteCompileCache { get; set; }
|
||||
/// <summary>
|
||||
/// 添加分库路由
|
||||
/// </summary>
|
||||
/// <param name="routeType"></param>
|
||||
void AddShardingDataSourceRoute(Type routeType);
|
||||
/// <summary>
|
||||
/// 添加分表路由
|
||||
/// </summary>
|
||||
/// <param name="routeType"></param>
|
||||
void AddShardingTableRoute(Type routeType);
|
||||
/// <summary>
|
||||
/// 是否有虚拟表路由
|
||||
/// </summary>
|
||||
/// <param name="entityType"></param>
|
||||
/// <returns></returns>
|
||||
bool HasVirtualTableRoute(Type entityType);
|
||||
/// <summary>
|
||||
/// 获取虚拟表路由
|
||||
/// </summary>
|
||||
/// <param name="entityType"></param>
|
||||
/// <returns></returns>
|
||||
Type GetVirtualTableRouteType(Type entityType);
|
||||
/// <summary>
|
||||
/// 是否有虚拟库路由
|
||||
/// </summary>
|
||||
/// <param name="entityType"></param>
|
||||
/// <returns></returns>
|
||||
bool HasVirtualDataSourceRoute(Type entityType);
|
||||
/// <summary>
|
||||
/// 获取虚拟库路由
|
||||
/// </summary>
|
||||
/// <param name="entityType"></param>
|
||||
/// <returns></returns>
|
||||
Type GetVirtualDataSourceRouteType(Type entityType);
|
||||
/// <summary>
|
||||
/// 获取所有的分表路由类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISet<Type> GetShardingTableRouteTypes();
|
||||
/// <summary>
|
||||
/// 获取所有的分库路由类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISet<Type> GetShardingDataSourceRouteTypes();
|
||||
|
||||
/// <summary>
|
||||
/// 平行表
|
||||
/// </summary>
|
||||
bool AddParallelTableGroupNode(ParallelTableGroupNode parallelTableGroupNode);
|
||||
/// <summary>
|
||||
/// 获取平行表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISet<ParallelTableGroupNode> GetParallelTableGroupNodes();
|
||||
/// <summary>
|
||||
/// DbContext如何通过现有connection创建
|
||||
/// </summary>
|
||||
Action<DbConnection, DbContextOptionsBuilder> ConnectionConfigure { get; }
|
||||
/// <summary>
|
||||
/// DbContext如何通过连接字符串创建
|
||||
/// </summary>
|
||||
Action<string, DbContextOptionsBuilder> ConnectionStringConfigure { get; }
|
||||
|
||||
/// <summary>
|
||||
/// DbContext如何通过连接字符串创建
|
||||
/// </summary>
|
||||
public void UseShardingQuery(Action<string, DbContextOptionsBuilder> queryConfigure);
|
||||
/// <summary>
|
||||
/// DbContext如何通过现有connection创建
|
||||
/// </summary>
|
||||
public void UseShardingTransaction(Action<DbConnection, DbContextOptionsBuilder> transactionConfigure);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Core.ShardingConfigurations.Abstractions
|
||||
{
|
||||
public interface IShardingEntityConfigOptions<TShardingDbContext> : IShardingEntityConfigOptions where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加分库路由
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoute"></typeparam>
|
||||
void AddShardingDataSourceRoute<TRoute>() where TRoute : IVirtualDataSourceRoute;
|
||||
/// <summary>
|
||||
/// 添加分表路由
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoute"></typeparam>
|
||||
void AddShardingTableRoute<TRoute>() where TRoute : IVirtualTableRoute;
|
||||
}
|
||||
}
|
|
@ -87,7 +87,7 @@ namespace ShardingCore.Core.ShardingConfigurations.ConfigBuilders
|
|||
{
|
||||
if (ShardingCoreConfigBuilder.ShardingConfigOptions.Count > 1)
|
||||
{
|
||||
throw new ArgumentException($"call {nameof(AddConfig)} at most once ");
|
||||
throw new ArgumentException($"plz call {nameof(AddConfig)} at most once ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,36 +95,40 @@ namespace ShardingCore.Core.ShardingConfigurations.ConfigBuilders
|
|||
services.AddSingleton<IDbContextTypeCollector>(sp => new DbContextTypeCollector<TShardingDbContext>());
|
||||
services.AddSingleton<IShardingEntityConfigOptions<TShardingDbContext>>(sp => ShardingCoreConfigBuilder.ShardingEntityConfigOptions);
|
||||
services.AddSingleton(sp => ShardingCoreConfigBuilder.ShardingEntityConfigOptions);
|
||||
if (!isMultiConfig)
|
||||
{
|
||||
services.AddSingleton<IShardingConfigurationOptions<TShardingDbContext>>(sp =>
|
||||
{
|
||||
var shardingSingleConfigurationOptions = new ShardingSingleConfigurationOptions<TShardingDbContext>();
|
||||
shardingSingleConfigurationOptions.ShardingConfigurationStrategy = configurationStrategy;
|
||||
shardingSingleConfigurationOptions.AddShardingGlobalConfigOptions(ShardingCoreConfigBuilder
|
||||
.ShardingConfigOptions.First());
|
||||
return shardingSingleConfigurationOptions;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddSingleton<IShardingConfigurationOptions<TShardingDbContext>>(sp =>
|
||||
{
|
||||
var shardingMultiConfigurationOptions = new ShardingMultiConfigurationOptions<TShardingDbContext>();
|
||||
shardingMultiConfigurationOptions.ShardingConfigurationStrategy = configurationStrategy;
|
||||
foreach (var shardingGlobalConfigOptions in ShardingCoreConfigBuilder
|
||||
.ShardingConfigOptions)
|
||||
{
|
||||
shardingMultiConfigurationOptions.AddShardingGlobalConfigOptions(shardingGlobalConfigOptions);
|
||||
}
|
||||
|
||||
return shardingMultiConfigurationOptions;
|
||||
});
|
||||
}
|
||||
services.AddSingleton(sp => CreateShardingConfigurationOptions(isMultiConfig, configurationStrategy));
|
||||
services.TryAddSingleton<IShardingReadWriteAccessor, ShardingReadWriteAccessor<TShardingDbContext>>();
|
||||
|
||||
services.AddInternalShardingCore();
|
||||
return services;
|
||||
}
|
||||
|
||||
private IShardingConfigurationOptions<TShardingDbContext> CreateShardingConfigurationOptions(bool isMultiConfig,
|
||||
ShardingConfigurationStrategyEnum configurationStrategy)
|
||||
{
|
||||
IShardingConfigurationOptions<TShardingDbContext> shardingConfigurationOptions;
|
||||
if (!isMultiConfig)
|
||||
{
|
||||
shardingConfigurationOptions = new ShardingSingleConfigurationOptions<TShardingDbContext>
|
||||
{
|
||||
ShardingConfigurationStrategy = configurationStrategy
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
shardingConfigurationOptions = new ShardingMultiConfigurationOptions<TShardingDbContext>
|
||||
{
|
||||
ShardingConfigurationStrategy = configurationStrategy
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var configOptions in ShardingCoreConfigBuilder
|
||||
.ShardingConfigOptions)
|
||||
{
|
||||
shardingConfigurationOptions.AddShardingGlobalConfigOptions(configOptions);
|
||||
}
|
||||
|
||||
return shardingConfigurationOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
using ShardingCore.Exceptions;
|
||||
|
@ -14,72 +15,10 @@ using ShardingCore.Sharding.ParallelTables;
|
|||
|
||||
namespace ShardingCore.Core.ShardingConfigurations
|
||||
{
|
||||
public interface IShardingEntityConfigOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 如果数据库不存在就创建并且创建表除了分表的
|
||||
/// </summary>
|
||||
bool EnsureCreatedWithOutShardingTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要在启动时创建分表
|
||||
/// </summary>
|
||||
bool? CreateShardingTableOnStart { get; set; }
|
||||
/// <summary>
|
||||
/// 当查询遇到没有路由被命中时是否抛出错误
|
||||
/// </summary>
|
||||
bool ThrowIfQueryRouteNotMatch { get; set; }
|
||||
/// <summary>
|
||||
/// 忽略建表时的错误
|
||||
/// </summary>
|
||||
bool? IgnoreCreateTableError { get; set; }
|
||||
bool? EnableTableRouteCompileCache { get; set; }
|
||||
bool? EnableDataSourceRouteCompileCache { get; set; }
|
||||
/// <summary>
|
||||
/// 添加分表路由
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoute"></typeparam>
|
||||
void AddShardingDataSourceRoute<TRoute>() where TRoute : IVirtualDataSourceRoute;
|
||||
void AddShardingDataSourceRoute(Type routeType);
|
||||
/// <summary>
|
||||
/// 添加分表路由
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoute"></typeparam>
|
||||
void AddShardingTableRoute<TRoute>() where TRoute : IVirtualTableRoute;
|
||||
void AddShardingTableRoute(Type routeType);
|
||||
|
||||
bool HasVirtualTableRoute(Type entityType);
|
||||
|
||||
Type GetVirtualTableRouteType(Type entityType);
|
||||
|
||||
bool HasVirtualDataSourceRoute(Type entityType);
|
||||
|
||||
Type GetVirtualDataSourceRouteType(Type entityType);
|
||||
|
||||
ISet<Type> GetShardingTableRouteTypes();
|
||||
|
||||
ISet<Type> GetShardingDataSourceRouteTypes();
|
||||
|
||||
/// <summary>
|
||||
/// 平行表
|
||||
/// </summary>
|
||||
bool AddParallelTableGroupNode(ParallelTableGroupNode parallelTableGroupNode);
|
||||
ISet<ParallelTableGroupNode> GetParallelTableGroupNodes();
|
||||
Action<DbConnection, DbContextOptionsBuilder> ConnectionConfigure { get; }
|
||||
Action<string, DbContextOptionsBuilder> ConnectionStringConfigure { get;}
|
||||
|
||||
|
||||
public void UseShardingQuery(Action<string, DbContextOptionsBuilder> queryConfigure);
|
||||
|
||||
public void UseShardingTransaction(Action<DbConnection, DbContextOptionsBuilder> transactionConfigure);
|
||||
}
|
||||
public interface IShardingEntityConfigOptions<TShardingDbContext>: IShardingEntityConfigOptions where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
}
|
||||
public class ShardingEntityConfigOptions<TShardingDbContext> : IShardingEntityConfigOptions<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
private readonly Dictionary<Type, Type> _virtualDataSourceRoutes = new Dictionary<Type, Type>();
|
||||
private readonly Dictionary<Type, Type> _virtualTableRoutes = new Dictionary<Type, Type>();
|
||||
private readonly IDictionary<Type, Type> _virtualDataSourceRoutes = new Dictionary<Type, Type>();
|
||||
private readonly IDictionary<Type, Type> _virtualTableRoutes = new Dictionary<Type, Type>();
|
||||
public readonly ISet<ParallelTableGroupNode> _parallelTables = new HashSet<ParallelTableGroupNode>();
|
||||
|
||||
/// <summary>
|
||||
|
@ -118,11 +57,11 @@ namespace ShardingCore.Core.ShardingConfigurations
|
|||
var genericVirtualRoute = routeType.GetInterfaces().FirstOrDefault(it => it.IsInterface && it.IsGenericType && it.GetGenericTypeDefinition() == typeof(IVirtualDataSourceRoute<>)
|
||||
&& it.GetGenericArguments().Any());
|
||||
if (genericVirtualRoute == null)
|
||||
throw new ArgumentException("add sharding route type error not assignable from IVirtualDataSourceRoute<>.");
|
||||
throw new ArgumentException($"add sharding route type error not assignable from {nameof(IVirtualDataSourceRoute<object>)}.");
|
||||
|
||||
var shardingEntityType = genericVirtualRoute.GetGenericArguments()[0];
|
||||
if (shardingEntityType == null)
|
||||
throw new ArgumentException("add sharding table route type error not assignable from IVirtualDataSourceRoute<>");
|
||||
throw new ArgumentException($"add sharding table route type error not assignable from {nameof(IVirtualDataSourceRoute<object>)}.");
|
||||
if (!_virtualDataSourceRoutes.ContainsKey(shardingEntityType))
|
||||
{
|
||||
_virtualDataSourceRoutes.Add(shardingEntityType, routeType);
|
||||
|
@ -145,11 +84,11 @@ namespace ShardingCore.Core.ShardingConfigurations
|
|||
var genericVirtualRoute = routeType.GetInterfaces().FirstOrDefault(it => it.IsInterface && it.IsGenericType && it.GetGenericTypeDefinition() == typeof(IVirtualTableRoute<>)
|
||||
&& it.GetGenericArguments().Any());
|
||||
if (genericVirtualRoute == null)
|
||||
throw new ArgumentException("add sharding route type error not assignable from IVirtualTableRoute<>.");
|
||||
throw new ArgumentException($"add sharding route type error not assignable from {nameof(IVirtualTableRoute<object>)}.");
|
||||
|
||||
var shardingEntityType = genericVirtualRoute.GetGenericArguments()[0];
|
||||
if (shardingEntityType == null)
|
||||
throw new ArgumentException("add sharding table route type error not assignable from IVirtualTableRoute<>");
|
||||
throw new ArgumentException($"add sharding table route type error not assignable from {nameof(IVirtualTableRoute<object>)}.");
|
||||
if (!_virtualTableRoutes.ContainsKey(shardingEntityType))
|
||||
{
|
||||
_virtualTableRoutes.Add(shardingEntityType, routeType);
|
||||
|
@ -164,7 +103,7 @@ namespace ShardingCore.Core.ShardingConfigurations
|
|||
public Type GetVirtualTableRouteType(Type entityType)
|
||||
{
|
||||
if (!_virtualTableRoutes.ContainsKey(entityType))
|
||||
throw new ArgumentException($"{entityType} not found IVirtualTableRoute");
|
||||
throw new ArgumentException($"{entityType} not found {nameof(IVirtualTableRoute)}");
|
||||
return _virtualTableRoutes[entityType];
|
||||
}
|
||||
|
||||
|
@ -176,7 +115,7 @@ namespace ShardingCore.Core.ShardingConfigurations
|
|||
public Type GetVirtualDataSourceRouteType(Type entityType)
|
||||
{
|
||||
if (!_virtualDataSourceRoutes.ContainsKey(entityType))
|
||||
throw new ArgumentException($"{entityType} not found IVirtualDataSourceRoute");
|
||||
throw new ArgumentException($"{entityType} not found {nameof(IVirtualDataSourceRoute)}");
|
||||
return _virtualDataSourceRoutes[entityType];
|
||||
}
|
||||
|
||||
|
@ -194,18 +133,34 @@ namespace ShardingCore.Core.ShardingConfigurations
|
|||
Check.NotNull(parallelTableGroupNode, $"{nameof(parallelTableGroupNode)}");
|
||||
return _parallelTables.Add(parallelTableGroupNode);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取平行表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ISet<ParallelTableGroupNode> GetParallelTableGroupNodes()
|
||||
{
|
||||
return _parallelTables;
|
||||
}
|
||||
/// <summary>
|
||||
/// DbContext如何通过现有connection创建
|
||||
/// </summary>
|
||||
public Action<DbConnection, DbContextOptionsBuilder> ConnectionConfigure { get; private set; }
|
||||
/// <summary>
|
||||
/// DbContext如何通过连接字符串创建
|
||||
/// </summary>
|
||||
public Action<string, DbContextOptionsBuilder> ConnectionStringConfigure { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// DbContext如何通过连接字符串创建
|
||||
/// </summary>
|
||||
public void UseShardingQuery(Action<string, DbContextOptionsBuilder> queryConfigure)
|
||||
{
|
||||
ConnectionStringConfigure = queryConfigure ?? throw new ArgumentNullException(nameof(queryConfigure));
|
||||
}
|
||||
/// <summary>
|
||||
/// DbContext如何通过现有connection创建
|
||||
/// </summary>
|
||||
public void UseShardingTransaction(Action<DbConnection, DbContextOptionsBuilder> transactionConfigure)
|
||||
{
|
||||
ConnectionConfigure = transactionConfigure ?? throw new ArgumentNullException(nameof(transactionConfigure));
|
||||
|
|
|
@ -12,6 +12,7 @@ using System.Collections.Concurrent;
|
|||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
|
||||
namespace ShardingCore.Core.VirtualDatabase.VirtualDataSources
|
||||
{
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.EntityShardingMetadatas;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Sharding.MergeEngines.ParallelControl;
|
||||
using ShardingCore.Sharding.PaginationConfigurations;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
|
||||
{
|
||||
|
|
|
@ -52,12 +52,12 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes
|
|||
|
||||
}
|
||||
|
||||
public interface IVirtualDataSourceRoute<T> : IVirtualDataSourceRoute, IEntityMetadataDataSourceConfiguration<T> where T : class
|
||||
public interface IVirtualDataSourceRoute<TEntity> : IVirtualDataSourceRoute, IEntityMetadataDataSourceConfiguration<TEntity> where TEntity : class
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回null就是表示不开启分页配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IPaginationConfiguration<T> CreatePaginationConfiguration();
|
||||
IPaginationConfiguration<TEntity> CreatePaginationConfiguration();
|
||||
}
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.PhysicTables;
|
||||
using ShardingCore.Core.QueryRouteManagers;
|
||||
using ShardingCore.Core.QueryRouteManagers.Abstractions;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.MergeEngines.ParallelControl;
|
||||
using ShardingCore.Sharding.PaginationConfigurations;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions
|
||||
{
|
||||
|
|
|
@ -68,14 +68,7 @@ namespace ShardingCore
|
|||
throw new NotSupportedException($"{nameof(contextLifetime)}:{nameof(ServiceLifetime.Singleton)}");
|
||||
if (optionsLifetime == ServiceLifetime.Singleton)
|
||||
throw new NotSupportedException($"{nameof(optionsLifetime)}:{nameof(ServiceLifetime.Singleton)}");
|
||||
Action<IServiceProvider, DbContextOptionsBuilder> shardingOptionAction = (sp, option) =>
|
||||
{
|
||||
var virtualDataSource = sp.GetRequiredService<IVirtualDataSourceManager<TShardingDbContext>>().GetCurrentVirtualDataSource();
|
||||
var connectionString = virtualDataSource.GetConnectionString(virtualDataSource.DefaultDataSourceName);
|
||||
virtualDataSource.ConfigurationParams.UseDbContextOptionsBuilder(connectionString, option);
|
||||
option.UseSharding<TShardingDbContext>();
|
||||
};
|
||||
services.AddDbContext<TShardingDbContext>(shardingOptionAction, contextLifetime, optionsLifetime);
|
||||
services.AddDbContext<TShardingDbContext>(UseDefaultSharding<TShardingDbContext>, contextLifetime, optionsLifetime);
|
||||
return services.AddShardingConfigure<TShardingDbContext>();
|
||||
}
|
||||
|
||||
|
@ -86,6 +79,12 @@ namespace ShardingCore
|
|||
return new ShardingCoreConfigBuilder<TShardingDbContext>(services);
|
||||
}
|
||||
|
||||
public static void UseDefaultSharding<TShardingDbContext>(IServiceProvider serviceProvider,DbContextOptionsBuilder dbContextOptionsBuilder) where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
var virtualDataSource = serviceProvider.GetRequiredService<IVirtualDataSourceManager<TShardingDbContext>>().GetCurrentVirtualDataSource();
|
||||
var connectionString = virtualDataSource.GetConnectionString(virtualDataSource.DefaultDataSourceName);
|
||||
virtualDataSource.ConfigurationParams.UseDbContextOptionsBuilder(connectionString, dbContextOptionsBuilder).UseSharding<TShardingDbContext>();
|
||||
}
|
||||
internal static IServiceCollection AddInternalShardingCore(this IServiceCollection services)
|
||||
{
|
||||
//虚拟数据源管理者
|
||||
|
|
|
@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.PhysicTables;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualTables;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using System;
|
||||
|
||||
namespace ShardingCore.Extensions
|
||||
{
|
||||
|
|
|
@ -1,20 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.ShardingExecutors.Abstractions;
|
||||
using ShardingCore.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.Sharding.ShardingExecutors
|
||||
{
|
||||
|
|
|
@ -4,10 +4,12 @@ using ShardingCore.Core.Internal.StreamMerge.ReWrite;
|
|||
using ShardingCore.Core.Internal.Visitors;
|
||||
using ShardingCore.Core.Internal.Visitors.GroupBys;
|
||||
using ShardingCore.Core.Internal.Visitors.Selects;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.TrackerManagers;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.RouteRuleEngine;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.ShardingComparision.Abstractions;
|
||||
|
@ -17,8 +19,6 @@ using System.Collections.Concurrent;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Exceptions;
|
||||
|
||||
|
||||
namespace ShardingCore.Sharding
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
@ -7,9 +10,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
|
||||
namespace ShardingCore
|
||||
{
|
||||
|
|
|
@ -3,19 +3,13 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Core.VirtualTables;
|
||||
using ShardingCore.DbContexts;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualTables;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
|
||||
namespace ShardingCore.TableCreator
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue