From b17a8416683d03122da8745b96242ad8ff3c54af Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Thu, 2 Jun 2022 12:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ValuesController.cs | 7 +++++ .../Domain/Entities/SysUserSalary.cs | 2 +- .../Shardings/SysUserModVirtualTableRoute.cs | 4 +-- .../SysUserSalaryPaginationConfiguration.cs | 3 ++ .../SysUserSalaryVirtualTableRoute.cs | 6 ++-- .../ActivatorDbContextCreator.cs | 13 ++++++-- .../DbContextCreator/IDbContextCreator.cs | 10 ++++-- .../ShardingDbContextOptions.cs | 1 - .../Core/PhysicTables/IPhysicTable.cs | 3 ++ .../VirtualRoutes/RoutePredicateExpression.cs | 31 +++++++++++++++++-- .../TableRoutes/IVirtualTableRoute.cs | 17 ++++++++++ src/ShardingCore/DIExtension.cs | 2 +- .../EFCores/ShardingQueryCompiler.cs | 27 +++++++--------- src/ShardingCore/IDbContextTypeCollector.cs | 3 ++ .../Abstractions/IShardingComplierExecutor.cs | 4 +-- .../EntityQueryBuilder.cs | 5 ++- .../QueryableMethodNameEnum.cs | 6 ++++ .../PaginationOrderPropertyBuilder.cs | 8 +++++ .../Abstractions/IQueryCompilerContext.cs | 9 ++++++ ....cs => DefaultShardingCompilerExecutor.cs} | 9 ++++-- src/ShardingCore/ShardingContainer.cs | 18 +++++++++++ 21 files changed, 151 insertions(+), 37 deletions(-) rename src/ShardingCore/Sharding/ShardingExecutors/{DefaultShardingComplierExecutor.cs => DefaultShardingCompilerExecutor.cs} (92%) diff --git a/samples/Sample.SqlServer/Controllers/ValuesController.cs b/samples/Sample.SqlServer/Controllers/ValuesController.cs index dda0297c..a18cd070 100644 --- a/samples/Sample.SqlServer/Controllers/ValuesController.cs +++ b/samples/Sample.SqlServer/Controllers/ValuesController.cs @@ -382,5 +382,12 @@ namespace Sample.SqlServer.Controllers return Ok(); } + [HttpGet] + public async Task Get6() + { + var sysUserSalaries = await _defaultTableDbContext.Set().Where(o=>o.DateOfMonth==202101).ToListAsync(); + return Ok(); + } + } } diff --git a/samples/Sample.SqlServer/Domain/Entities/SysUserSalary.cs b/samples/Sample.SqlServer/Domain/Entities/SysUserSalary.cs index ea33df96..7373eb5e 100644 --- a/samples/Sample.SqlServer/Domain/Entities/SysUserSalary.cs +++ b/samples/Sample.SqlServer/Domain/Entities/SysUserSalary.cs @@ -16,7 +16,7 @@ namespace Sample.SqlServer.Domain.Entities /// 每月的金额 /// [ShardingTableKey] - public int DateOfMonth { get; set; } + public int? DateOfMonth { get; set; } /// /// 工资 /// diff --git a/samples/Sample.SqlServer/Shardings/SysUserModVirtualTableRoute.cs b/samples/Sample.SqlServer/Shardings/SysUserModVirtualTableRoute.cs index 2e3d8cea..84a237a9 100644 --- a/samples/Sample.SqlServer/Shardings/SysUserModVirtualTableRoute.cs +++ b/samples/Sample.SqlServer/Shardings/SysUserModVirtualTableRoute.cs @@ -14,11 +14,11 @@ namespace Sample.SqlServer.Shardings public class SysUserModVirtualTableRoute : AbstractSimpleShardingModKeyStringVirtualTableRoute { /// - /// ʾ· + /// 开启提示路由 /// protected override bool EnableHintRoute => true; /// - /// · + /// 开启断言路由 /// protected override bool EnableAssertRoute => true; diff --git a/samples/Sample.SqlServer/Shardings/SysUserSalaryPaginationConfiguration.cs b/samples/Sample.SqlServer/Shardings/SysUserSalaryPaginationConfiguration.cs index 3a937d25..75b9918f 100644 --- a/samples/Sample.SqlServer/Shardings/SysUserSalaryPaginationConfiguration.cs +++ b/samples/Sample.SqlServer/Shardings/SysUserSalaryPaginationConfiguration.cs @@ -14,9 +14,12 @@ namespace Sample.SqlServer.Shardings builder.PaginationSequence(o => o.Id) .UseRouteComparer(Comparer.Default) .UseQueryMatch(PaginationMatchEnum.Owner | PaginationMatchEnum.Named | PaginationMatchEnum.PrimaryMatch); + //设置当 builder.PaginationSequence(o => o.DateOfMonth) + .UseRouteComparer(Comparer.Default) .UseQueryMatch(PaginationMatchEnum.Owner | PaginationMatchEnum.Named | PaginationMatchEnum.PrimaryMatch).UseAppendIfOrderNone(10); builder.PaginationSequence(o => o.Salary) + .UseRouteComparer(Comparer.Default) .UseQueryMatch(PaginationMatchEnum.Owner | PaginationMatchEnum.Named | PaginationMatchEnum.PrimaryMatch).UseAppendIfOrderNone(); builder.ConfigReverseShardingPage(0.5d,10000L); } diff --git a/samples/Sample.SqlServer/Shardings/SysUserSalaryVirtualTableRoute.cs b/samples/Sample.SqlServer/Shardings/SysUserSalaryVirtualTableRoute.cs index 4f90af0a..c2be71fa 100644 --- a/samples/Sample.SqlServer/Shardings/SysUserSalaryVirtualTableRoute.cs +++ b/samples/Sample.SqlServer/Shardings/SysUserSalaryVirtualTableRoute.cs @@ -16,7 +16,7 @@ namespace Sample.SqlServer.Shardings * @Date: Monday, 01 February 2021 15:54:55 * @Email: 326308290@qq.com */ - public class SysUserSalaryVirtualTableRoute:AbstractShardingOperatorVirtualTableRoute + public class SysUserSalaryVirtualTableRoute:AbstractShardingOperatorVirtualTableRoute { public override string ShardingKeyToTail(object shardingKey) @@ -46,13 +46,13 @@ namespace Sample.SqlServer.Shardings } - protected string TimeFormatToTail(int time) + protected string TimeFormatToTail(int? time) { var dateOfMonth=DateTime.ParseExact($"{time}","yyyyMM",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.AdjustToUniversal); return $"{dateOfMonth:yyyyMM}"; } - public override Func GetRouteToFilter(int shardingKey, ShardingOperatorEnum shardingOperator) + public override Func GetRouteToFilter(int? shardingKey, ShardingOperatorEnum shardingOperator) { var t = TimeFormatToTail(shardingKey); switch (shardingOperator) diff --git a/src/ShardingCore/Core/DbContextCreator/ActivatorDbContextCreator.cs b/src/ShardingCore/Core/DbContextCreator/ActivatorDbContextCreator.cs index 48e29081..2ab17c73 100644 --- a/src/ShardingCore/Core/DbContextCreator/ActivatorDbContextCreator.cs +++ b/src/ShardingCore/Core/DbContextCreator/ActivatorDbContextCreator.cs @@ -12,7 +12,10 @@ using ShardingCore.Sharding.Abstractions; namespace ShardingCore.Core.DbContextCreator { /// - /// + /// dbcontext的创建者 + /// 反射创建默认框架采用这个可以, + /// 如果需要dbcontext构造函数支持依赖注入参数 + /// 可以自行重写这个接口 /// /// Author: xjm /// Created: 2022/4/2 21:15:09 @@ -25,7 +28,13 @@ namespace ShardingCore.Core.DbContextCreator ShardingCoreHelper.CheckContextConstructors(); _creator = ShardingCoreHelper.CreateActivator(); } - public DbContext CreateDbContext(DbContext mainDbContext, ShardingDbContextOptions shardingDbContextOptions) + /// + /// 如何创建dbcontext + /// + /// + /// + /// + public DbContext CreateDbContext(DbContext shellDbContext, ShardingDbContextOptions shardingDbContextOptions) { var dbContext = _creator(shardingDbContextOptions); if (dbContext is IShardingTableDbContext shardingTableDbContext) diff --git a/src/ShardingCore/Core/DbContextCreator/IDbContextCreator.cs b/src/ShardingCore/Core/DbContextCreator/IDbContextCreator.cs index d13c3377..f681468a 100644 --- a/src/ShardingCore/Core/DbContextCreator/IDbContextCreator.cs +++ b/src/ShardingCore/Core/DbContextCreator/IDbContextCreator.cs @@ -11,14 +11,20 @@ using ShardingCore.Sharding.Abstractions; namespace ShardingCore.Core.DbContextCreator { /// - /// + /// dbcontext创建者 /// /// Author: xjm /// Created: 2022/4/2 21:12:17 /// Email: 326308290@qq.com public interface IDbContextCreator { - public DbContext CreateDbContext(DbContext mainDbContext, ShardingDbContextOptions shardingDbContextOptions); + /// + /// 创建dbcontext + /// + /// 最外部的dbcontext也就是壳不具备真正的执行 + /// 返回dbcontext的配置路由等信息 + /// + public DbContext CreateDbContext(DbContext shellDbContext, ShardingDbContextOptions shardingDbContextOptions); } public interface IDbContextCreator : IDbContextCreator diff --git a/src/ShardingCore/Core/DbContextCreator/ShardingDbContextOptions.cs b/src/ShardingCore/Core/DbContextCreator/ShardingDbContextOptions.cs index b9ff9ec6..da63b6ee 100644 --- a/src/ShardingCore/Core/DbContextCreator/ShardingDbContextOptions.cs +++ b/src/ShardingCore/Core/DbContextCreator/ShardingDbContextOptions.cs @@ -13,7 +13,6 @@ namespace ShardingCore.Core.DbContextCreator */ public class ShardingDbContextOptions { - public ShardingDbContextOptions(DbContextOptions dbContextOptions, IRouteTail routeTail) { RouteTail = routeTail; diff --git a/src/ShardingCore/Core/PhysicTables/IPhysicTable.cs b/src/ShardingCore/Core/PhysicTables/IPhysicTable.cs index e31e3b1e..aae38c07 100644 --- a/src/ShardingCore/Core/PhysicTables/IPhysicTable.cs +++ b/src/ShardingCore/Core/PhysicTables/IPhysicTable.cs @@ -15,6 +15,9 @@ namespace ShardingCore.Core.PhysicTables /// public interface IPhysicTable { + /// + /// 对象信息 + /// EntityMetadata EntityMetadata { get; } /// /// 表全称 diff --git a/src/ShardingCore/Core/VirtualRoutes/RoutePredicateExpression.cs b/src/ShardingCore/Core/VirtualRoutes/RoutePredicateExpression.cs index 38601038..92640fca 100644 --- a/src/ShardingCore/Core/VirtualRoutes/RoutePredicateExpression.cs +++ b/src/ShardingCore/Core/VirtualRoutes/RoutePredicateExpression.cs @@ -2,29 +2,50 @@ using System; namespace ShardingCore.Core.VirtualRoutes { - + /// + /// 高性能路由条件组合委托 + /// 无需compile支持路由条件直接组合and 和 or + /// public class RoutePredicateExpression { private static readonly Func _defaultRoutePredicate = tail => true; private static readonly Func _defaultFalseRoutePredicate = tail => false; + /// + /// 默认创建一个true委托 + /// + public static RoutePredicateExpression Default => new RoutePredicateExpression(); + /// + /// 默认创建一个false委托 + /// + public static RoutePredicateExpression DefaultFalse => new RoutePredicateExpression(_defaultFalseRoutePredicate); + + private readonly Func _routePredicate; public RoutePredicateExpression():this(_defaultRoutePredicate) { } - public static RoutePredicateExpression Default => new RoutePredicateExpression(); - public static RoutePredicateExpression DefaultFalse => new RoutePredicateExpression(_defaultFalseRoutePredicate); public RoutePredicateExpression(Func routePredicate) { _routePredicate = routePredicate??throw new ArgumentNullException(nameof(routePredicate)); } + /// + /// and链接当前委托和外部传入的委托 + /// + /// + /// public RoutePredicateExpression And(RoutePredicateExpression routePredicateExpression) { var routePredicate = routePredicateExpression.GetRoutePredicate(); Func func = tail => _routePredicate(tail)&&routePredicate(tail); return new RoutePredicateExpression(func); } + /// + /// or链接当前委托和外部传入的委托 + /// + /// + /// public RoutePredicateExpression Or(RoutePredicateExpression routePredicateExpression) { var routePredicate = routePredicateExpression.GetRoutePredicate(); @@ -32,6 +53,10 @@ namespace ShardingCore.Core.VirtualRoutes return new RoutePredicateExpression(func); } + /// + /// 返回当前表达式的路由委托条件 + /// + /// public Func GetRoutePredicate() { return _routePredicate; diff --git a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/IVirtualTableRoute.cs b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/IVirtualTableRoute.cs index b3ce6004..3a4e3056 100644 --- a/src/ShardingCore/Core/VirtualRoutes/TableRoutes/IVirtualTableRoute.cs +++ b/src/ShardingCore/Core/VirtualRoutes/TableRoutes/IVirtualTableRoute.cs @@ -51,11 +51,28 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes { /// /// 返回null就是表示不开启分页配置 + /// 譬如如下配置 + /// o.DateOfMonth) + /// .UseRouteComparer(Comparer.Default) + /// .UseQueryMatch(PaginationMatchEnum.Owner | PaginationMatchEnum.Named | PaginationMatchEnum.PrimaryMatch) + /// .UseAppendIfOrderNone(10);]]> + /// 表示当前分页配置如果使用DateOfMonth属性排序并且只要符合属性属于这个对象或者名称一样并且只要是第一个排序即可 + /// 当前排序将可以使用高性能排序,这边需要设置一个当前属性DateOfMonth order by asc的时候当前分表多表是如何排序的 /// /// IPaginationConfiguration CreatePaginationConfiguration(); /// /// 配置查询 + /// .Default, false); + /// //表示他是倒叙 + /// builder.AddOrder(o => o.DateOfMonth, false); + /// // + /// builder.AddDefaultSequenceQueryTrip(false, CircuitBreakerMethodNameEnum.FirstOrDefault, CircuitBreakerMethodNameEnum.Enumerator); + /// + /// builder.AddConnectionsLimit(2, LimitMethodNameEnum.First, LimitMethodNameEnum.FirstOrDefault, LimitMethodNameEnum.Any, LimitMethodNameEnum.LastOrDefault, LimitMethodNameEnum.Last, LimitMethodNameEnum.Max, LimitMethodNameEnum.Min); + /// builder.AddConnectionsLimit(1, LimitMethodNameEnum.Enumerator);]]> /// /// IEntityQueryConfiguration CreateEntityQueryConfiguration(); diff --git a/src/ShardingCore/DIExtension.cs b/src/ShardingCore/DIExtension.cs index 067293e6..38b396eb 100644 --- a/src/ShardingCore/DIExtension.cs +++ b/src/ShardingCore/DIExtension.cs @@ -122,7 +122,7 @@ namespace ShardingCore //分表引擎工程 services.TryAddSingleton, ParallelTableManager>(); services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/src/ShardingCore/EFCores/ShardingQueryCompiler.cs b/src/ShardingCore/EFCores/ShardingQueryCompiler.cs index 8055d0b9..8b2cf45f 100644 --- a/src/ShardingCore/EFCores/ShardingQueryCompiler.cs +++ b/src/ShardingCore/EFCores/ShardingQueryCompiler.cs @@ -14,26 +14,24 @@ using System.Threading.Tasks; namespace ShardingCore.EFCores { - /** - * 描述: - * - * Author:xuejiaming - * Created: 2020/12/28 13:58:46 - **/ + /// + /// 当前查询编译拦截 + /// public class ShardingQueryCompiler : IQueryCompiler { private readonly IShardingDbContext _shardingDbContext; - private readonly IShardingComplierExecutor _shardingComplierExecutor; + private readonly IShardingCompilerExecutor _shardingCompilerExecutor; public ShardingQueryCompiler(ICurrentDbContext currentContext) { - _shardingDbContext = currentContext.Context as IShardingDbContext?? throw new ShardingCoreException("db context operator is not IShardingDbContext"); - _shardingComplierExecutor = ShardingContainer.GetService(); + _shardingDbContext = currentContext.Context as IShardingDbContext ?? + throw new ShardingCoreException("db context operator is not IShardingDbContext"); + _shardingCompilerExecutor = ShardingContainer.GetService(); } public TResult Execute(Expression query) { - return _shardingComplierExecutor.Execute(_shardingDbContext, query); + return _shardingCompilerExecutor.Execute(_shardingDbContext, query); } @@ -41,7 +39,7 @@ namespace ShardingCore.EFCores public TResult ExecuteAsync(Expression query, CancellationToken cancellationToken) { - return _shardingComplierExecutor.ExecuteAsync(_shardingDbContext, query, cancellationToken); + return _shardingCompilerExecutor.ExecuteAsync(_shardingDbContext, query, cancellationToken); } [ExcludeFromCodeCoverage] @@ -59,16 +57,14 @@ namespace ShardingCore.EFCores #endif #if EFCORE2 - - public IAsyncEnumerable ExecuteAsync(Expression query) { - return _shardingComplierExecutor.ExecuteAsync(_shardingDbContext, query); + return _shardingCompilerExecutor.ExecuteAsync(_shardingDbContext, query); } public Task ExecuteAsync(Expression query, CancellationToken cancellationToken) { - return _shardingComplierExecutor.ExecuteAsync(_shardingDbContext, query, cancellationToken); + return _shardingCompilerExecutor.ExecuteAsync(_shardingDbContext, query, cancellationToken); } [ExcludeFromCodeCoverage] @@ -89,6 +85,5 @@ namespace ShardingCore.EFCores throw new NotImplementedException(); } #endif - } } \ No newline at end of file diff --git a/src/ShardingCore/IDbContextTypeCollector.cs b/src/ShardingCore/IDbContextTypeCollector.cs index 192377e7..6fa1f1dc 100644 --- a/src/ShardingCore/IDbContextTypeCollector.cs +++ b/src/ShardingCore/IDbContextTypeCollector.cs @@ -8,6 +8,9 @@ using ShardingCore.Sharding.Abstractions; namespace ShardingCore { + /// + /// 启动dbContext类型收集器用于初始化确定dbcontext 类型 + /// public interface IDbContextTypeCollector { Type ShardingDbContextType { get; } diff --git a/src/ShardingCore/Sharding/Abstractions/IShardingComplierExecutor.cs b/src/ShardingCore/Sharding/Abstractions/IShardingComplierExecutor.cs index 57ecb54d..173f6365 100644 --- a/src/ShardingCore/Sharding/Abstractions/IShardingComplierExecutor.cs +++ b/src/ShardingCore/Sharding/Abstractions/IShardingComplierExecutor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; namespace ShardingCore.Sharding.Abstractions { - public interface IShardingComplierExecutor + public interface IShardingCompilerExecutor { /// diff --git a/src/ShardingCore/Sharding/EntityQueryConfigurations/EntityQueryBuilder.cs b/src/ShardingCore/Sharding/EntityQueryConfigurations/EntityQueryBuilder.cs index da7c35b2..4f1da019 100644 --- a/src/ShardingCore/Sharding/EntityQueryConfigurations/EntityQueryBuilder.cs +++ b/src/ShardingCore/Sharding/EntityQueryConfigurations/EntityQueryBuilder.cs @@ -13,6 +13,10 @@ using Microsoft.EntityFrameworkCore.Internal; namespace ShardingCore.Sharding.EntityQueryConfigurations { + /// + /// 对象查询配置 + /// + /// public class EntityQueryBuilder where TEntity : class { private readonly EntityQueryMetadata _entityQueryMetadata; @@ -78,7 +82,6 @@ namespace ShardingCore.Sharding.EntityQueryConfigurations /// public EntityQueryBuilder AddDefaultSequenceQueryTrip(bool isSameAsShardingTailComparer,params CircuitBreakerMethodNameEnum[] methodNames) { - foreach (var methodName in methodNames) { _entityQueryMetadata.AddDefaultSequenceQueryTrip(isSameAsShardingTailComparer, methodName); diff --git a/src/ShardingCore/Sharding/EntityQueryConfigurations/QueryableMethodNameEnum.cs b/src/ShardingCore/Sharding/EntityQueryConfigurations/QueryableMethodNameEnum.cs index 3a0deb09..429eae0f 100644 --- a/src/ShardingCore/Sharding/EntityQueryConfigurations/QueryableMethodNameEnum.cs +++ b/src/ShardingCore/Sharding/EntityQueryConfigurations/QueryableMethodNameEnum.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace ShardingCore.Sharding.EntityQueryConfigurations { + /// + /// 可以熔断的方法名 + /// public enum CircuitBreakerMethodNameEnum { First, @@ -19,6 +22,9 @@ namespace ShardingCore.Sharding.EntityQueryConfigurations Contains, Enumerator } + /// + /// 配置限制最大连接数的方法名 + /// public enum LimitMethodNameEnum { First, diff --git a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs index a3d64b67..f94c94bd 100644 --- a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs +++ b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs @@ -22,9 +22,17 @@ namespace ShardingCore.Sharding.PaginationConfigurations /// /// 使用哪个后缀比较 + /// 设置的比较器是asc的情况下 /// /// /// + public PaginationOrderPropertyBuilder UseRouteComparerAsc(IComparer routeComparer) + { + + _paginationSequenceConfig.RouteComparer= routeComparer ?? throw new ArgumentException(nameof(routeComparer)); + return this; + } + [Obsolete("plz use UseRouteComparerAsc")] public PaginationOrderPropertyBuilder UseRouteComparer(IComparer routeComparer) { diff --git a/src/ShardingCore/Sharding/ShardingExecutors/Abstractions/IQueryCompilerContext.cs b/src/ShardingCore/Sharding/ShardingExecutors/Abstractions/IQueryCompilerContext.cs index a5df7986..857ee198 100644 --- a/src/ShardingCore/Sharding/ShardingExecutors/Abstractions/IQueryCompilerContext.cs +++ b/src/ShardingCore/Sharding/ShardingExecutors/Abstractions/IQueryCompilerContext.cs @@ -19,6 +19,15 @@ namespace ShardingCore.Sharding.ShardingExecutors.Abstractions Expression GetQueryExpression(); IEntityMetadataManager GetEntityMetadataManager(); Type GetShardingDbContextType(); + /// + /// 如果当前是QueryCompilerContext + /// 获取编译后的执行结果,如果当前是没有分表分库 + /// 直接返回默认的dbcontext并且替换内部所有的dbcontext为执行dbcontext,简单理解为原生查询 + /// 如果当前是MergeQueryCompilerContext + /// 获取编译的执行结果,如果当前是有分表分库 + /// 但是如果是只涉及到一张表那么也可以简单理解为原生查询 + /// + /// QueryCompilerExecutor GetQueryCompilerExecutor(); bool IsEnumerableQuery(); diff --git a/src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingComplierExecutor.cs b/src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingCompilerExecutor.cs similarity index 92% rename from src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingComplierExecutor.cs rename to src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingCompilerExecutor.cs index 8d197f76..6f992e50 100644 --- a/src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingComplierExecutor.cs +++ b/src/ShardingCore/Sharding/ShardingExecutors/DefaultShardingCompilerExecutor.cs @@ -12,14 +12,17 @@ using ShardingCore.ShardingExecutors; namespace ShardingCore.Sharding.ShardingExecutors { - public class DefaultShardingComplierExecutor: IShardingComplierExecutor + /// + /// 默认的分片编译执行者 + /// + public class DefaultShardingCompilerExecutor: IShardingCompilerExecutor { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IShardingTrackQueryExecutor _shardingTrackQueryExecutor; private readonly IQueryCompilerContextFactory _queryCompilerContextFactory; private readonly IPrepareParser _prepareParser; - public DefaultShardingComplierExecutor(ILogger logger, + public DefaultShardingCompilerExecutor(ILogger logger, IShardingTrackQueryExecutor shardingTrackQueryExecutor, IQueryCompilerContextFactory queryCompilerContextFactory,IPrepareParser prepareParser) { _logger = logger; diff --git a/src/ShardingCore/ShardingContainer.cs b/src/ShardingCore/ShardingContainer.cs index c322ecd3..2f8a6618 100644 --- a/src/ShardingCore/ShardingContainer.cs +++ b/src/ShardingCore/ShardingContainer.cs @@ -22,6 +22,9 @@ namespace ShardingCore * @Date: Saturday, 02 January 2021 19:37:27 * @Email: 326308290@qq.com */ + /// + /// 分片容器全局唯一提供静态依赖注入IServiceProvider + /// public class ShardingContainer { private ShardingContainer() @@ -45,14 +48,29 @@ namespace ShardingCore serviceProvider = services; } + /// + /// 获取服务 + /// + /// + /// public static T GetService() { return ServiceProvider.GetService(); } + /// + /// 获取服务集合 + /// + /// + /// public static IEnumerable GetServices() { return ServiceProvider.GetServices(); } + /// + /// 根据类型获取服务 + /// + /// + /// public static object GetService(Type serviceType) { return ServiceProvider.GetService(serviceType);