移除命名空间和不必要的参数

This commit is contained in:
xuejiaming 2022-07-08 08:45:57 +08:00
parent 14e6a1d4a5
commit 86455805f0
23 changed files with 150 additions and 231 deletions

View File

@ -4,8 +4,9 @@
<!--默认统一输出XML注释文档不需要输出的项目可以单独关闭-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>xuejmnet</Authors>
<RepositoryUrl>https://github.com/xuejmnet/sharding-core</RepositoryUrl>
<RepositoryUrl>https://github.com/dotnetcore/sharding-core</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/dotnetcore/sharding-core</PackageProjectUrl>
<Company>xuejm</Company>
<LangVersion>10.0</LangVersion>
<Description>high performance lightweight solution for efcore sharding table and sharding database support read-write-separation </Description>

View File

@ -14,7 +14,7 @@ using ShardingCore.Extensions;
using ShardingCore.Helpers;
using ShardingCore.Jobs;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Abstractions;
/*

View File

@ -13,7 +13,7 @@ using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Jobs;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Logger;
using ShardingCore.Sharding.MergeEngines.ParallelControl;
using ShardingCore.Sharding.ParallelTables;

View File

@ -9,7 +9,7 @@ using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Jobs;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Logger;
using ShardingCore.Sharding.MergeEngines.ParallelControl;
using ShardingCore.Sharding.ParallelTables;
@ -25,9 +25,9 @@ namespace ShardingCore.Bootstrappers
private readonly IParallelTableManager _parallelTableManager;
private readonly DoOnlyOnce _doOnlyOnce = new DoOnlyOnce();
public ShardingInitializer(IShardingProvider shardingProvider)
public ShardingInitializer(IShardingProvider shardingProvider,ILogger<ShardingBootstrapper> logger)
{
_logger = ShardingLoggerFactory.DefaultFactory.CreateLogger<ShardingBootstrapper>();
_logger = logger;
_shardingProvider = shardingProvider;
_routeConfigOptions = shardingProvider.GetRequiredService<IShardingRouteConfigOptions>();
_entityMetadataManager = shardingProvider.GetRequiredService<IEntityMetadataManager>();

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Sharding.Abstractions;
@ -16,6 +17,7 @@ namespace ShardingCore.Core.EntityMetadatas
public class DefaultEntityMetadataManager : IEntityMetadataManager
{
private readonly ConcurrentDictionary<Type, EntityMetadata> _caches = new();
private readonly ConcurrentDictionary<string/*logic table name*/, EntityMetadata> _logicTableCaches = new();
public bool AddEntityMetadata(EntityMetadata entityMetadata)
{
@ -70,7 +72,11 @@ namespace ShardingCore.Core.EntityMetadatas
public EntityMetadata TryGetByLogicTableName(string logicTableName)
{
return _caches.Values.FirstOrDefault(o => o.LogicTableName == logicTableName);
if (_logicTableCaches.TryGetValue(logicTableName, out var metadata))
{
return metadata;
}
return null;
}
/// <summary>
@ -99,6 +105,16 @@ namespace ShardingCore.Core.EntityMetadatas
if (_caches.TryGetValue(efEntityType.ClrType, out var metadata))
{
metadata.SetEntityModel(efEntityType);
if (string.IsNullOrWhiteSpace(metadata.LogicTableName))
{
throw new ShardingCoreInvalidOperationException(
$"init model error, cant get logic table name:[{metadata.LogicTableName}] from entity:[{efEntityType.ClrType}]");
}
if (!_logicTableCaches.TryAdd(metadata.LogicTableName, metadata))
{
throw new ShardingCoreInvalidOperationException(
$"cant add logic table name caches for metadata:[{metadata.LogicTableName}-{efEntityType.ClrType}]");
}
return true;
}

View File

@ -54,7 +54,6 @@ namespace ShardingCore.Core.RuntimeContexts
void CheckRequirement();
void GetOrCreateShardingRuntimeModel(DbContext dbContext);
void Initialize();
void AutoShardingCreate();
object GetService(Type serviceType);

View File

@ -19,7 +19,7 @@ using ShardingCore.Core.VirtualRoutes.Abstractions;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.DynamicDataSources;
using ShardingCore.Exceptions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.Sharding.ParallelTables;
using ShardingCore.Sharding.ReadWriteConfigurations.Abstractions;
@ -254,12 +254,6 @@ namespace ShardingCore.Core.RuntimeContexts
}
}
}
//
// public void UseLogfactory(ILoggerFactory loggerFactory)
// {
// // ShardingLoggerFactory.DefaultFactory = loggerFactory;
// _applicationLoggerFactory = loggerFactory;
// }
private void CheckIfBuild()

View File

@ -8,7 +8,6 @@ namespace ShardingCore.Core.ServiceProviders
/// </summary>
public interface IShardingProvider
{
void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider);
/// <summary>
/// 优先通过ShardingCore的IServiceProvider获取
/// 没有再通过ApplicationServiceProvider获取

View File

@ -15,11 +15,6 @@ namespace ShardingCore.Core.ServiceProviders
_applicationServiceProvider = applicationServiceProvider;
}
public void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider)
{
_applicationServiceProvider = applicationServiceProvider;
}
public object GetService(Type serviceType,bool tryApplicationServiceProvider=true)
{
var service = _internalServiceProvider?.GetService(serviceType);

View File

@ -87,22 +87,12 @@ namespace ShardingCore.Core.VirtualDatabase.VirtualDataSources
public override void UseShellDbContextOptionBuilder(DbContextOptionsBuilder dbContextOptionsBuilder)
{
if (_options.ShellDbContextConfigure == null)
{
return;
}
_options.ShellDbContextConfigure.Invoke(dbContextOptionsBuilder);
_options.ShellDbContextConfigure?.Invoke(dbContextOptionsBuilder);
}
public override void UseExecutorDbContextOptionBuilder(DbContextOptionsBuilder dbContextOptionsBuilder)
{
if (_options.ExecutorDbContextConfigure == null )
{
return;
}
_options.ExecutorDbContextConfigure.Invoke(dbContextOptionsBuilder);
_options.ExecutorDbContextConfigure?.Invoke(dbContextOptionsBuilder);
}
}
}

View File

@ -16,7 +16,7 @@ using ShardingCore.Core.VirtualRoutes.Abstractions;
using ShardingCore.Core.VirtualRoutes.TableRoutes;
using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.TableExists.Abstractions;

View File

@ -12,7 +12,7 @@ using ShardingCore.Core.EntityMetadatas;
using ShardingCore.Core.RuntimeContexts;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Extensions.InternalExtensions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.Utils;

View File

@ -32,108 +32,59 @@ namespace ShardingCore.Helpers
[ExcludeFromCodeCoverage]
public class MigrationHelper
{
private MigrationHelper() { }
private MigrationHelper()
{
}
public static void Generate(
IShardingRuntimeContext shardingRuntimeContext,
MigrationOperation operation,
MigrationCommandListBuilder builder,
ISqlGenerationHelper sqlGenerationHelper,
List<MigrationCommand> addCmds
)
)
{
var migrationCommands = (List<MigrationCommand>) builder.GetFieldValue("_commands");
var migrationCommands = (List<MigrationCommand>)builder.GetFieldValue("_commands");
var shardingMigrationManager = shardingRuntimeContext.GetRequiredService<IShardingMigrationManager>();
var virtualDataSource = shardingRuntimeContext.GetRequiredService<IVirtualDataSource>();
var currentCurrentDataSourceName = shardingMigrationManager.Current?.CurrentDataSourceName??virtualDataSource.DefaultDataSourceName;
var currentCurrentDataSourceName = shardingMigrationManager.Current?.CurrentDataSourceName ??
virtualDataSource.DefaultDataSourceName;
addCmds.ForEach(aAddCmd =>
{
var (migrationResult, shardingCmds) = BuildDataSourceShardingCmds(shardingRuntimeContext,
virtualDataSource.DefaultDataSourceName, currentCurrentDataSourceName, operation,
aAddCmd.CommandText, sqlGenerationHelper);
if (!migrationResult.InDataSource)
{
var (migrationResult,shardingCmds) = BuildDataSourceShardingCmds(shardingRuntimeContext,virtualDataSource.DefaultDataSourceName,currentCurrentDataSourceName,operation, aAddCmd.CommandText, sqlGenerationHelper);
if (!migrationResult.InDataSource)
if (migrationResult.CommandType == MigrationCommandTypeEnum.TableCommand)
{
if (migrationResult.CommandType == MigrationCommandTypeEnum.TableCommand)
migrationCommands.Remove(aAddCmd);
}
}
else
{
if (migrationResult.CommandType == MigrationCommandTypeEnum.TableCommand)
{
//如果是分表
if (shardingCmds.IsNotEmpty())
{
migrationCommands.Remove(aAddCmd);
}
}
else
{
if (migrationResult.CommandType == MigrationCommandTypeEnum.TableCommand)
{
//如果是分表
if (shardingCmds.IsNotEmpty())
//针对builder的原始表进行移除
shardingCmds.ForEach(aShardingCmd =>
{
migrationCommands.Remove(aAddCmd);
//针对builder的原始表进行移除
shardingCmds.ForEach(aShardingCmd =>
{
builder.Append(aShardingCmd)
.EndCommand();
});
}
builder.Append(aShardingCmd)
.EndCommand();
});
}
}
});
}
});
}
private static List<string> BuildShardingCmds(IShardingRuntimeContext shardingRuntimeContext,MigrationOperation operation, string sourceCmd, ISqlGenerationHelper sqlGenerationHelper)
{
//所有MigrationOperation定义
//https://github.com/dotnet/efcore/tree/b970bf29a46521f40862a01db9e276e6448d3cb0/src/EFCore.Relational/Migrations/Operations
//ColumnOperation仅替换Table
//其余其余都是将Name和Table使用分表名替换
var tableRouteManager = shardingRuntimeContext.GetTableRouteManager();
var tableRoutes = tableRouteManager.GetRoutes();
var existsShardingTables = tableRoutes.ToDictionary(o => o.EntityMetadata.LogicTableName, o => o.GetTails().Select(p=>$"{o.EntityMetadata.LogicTableName}{o.EntityMetadata.TableSeparator}{p}").ToList());
//Dictionary<string, List<string>> _existsShardingTables
// = Cache.ServiceProvider.GetService<ShardingContainer>().ExistsShardingTables;
List<string> resList = new List<string>();
string absTableName = string.Empty;
string name = operation.GetPropertyValue("Name") as string;
string tableName = operation.GetPropertyValue("Table") as string;
string pattern = string.Format("^({0})$|^({0}_.*?)$|^(.*?_{0}_.*?)$|^(.*?_{0})$", absTableName);
Func<KeyValuePair<string, List<string>>, bool> where = x =>
existsShardingTables.Any(y =>x.Key==y.Key&& Regex.IsMatch(name, BuildPattern(y.Key)));
if (!string.IsNullOrWhiteSpace(tableName))
{
absTableName = tableName;
}
else if (!string.IsNullOrWhiteSpace(name) && existsShardingTables.Any(x => where(x)))
{
absTableName = existsShardingTables.Where(x => where(x)).FirstOrDefault().Key;
}
//分表
if (!string.IsNullOrWhiteSpace(absTableName) && existsShardingTables.ContainsKey(absTableName))
{
var shardings = existsShardingTables[absTableName];
shardings.ForEach(aShardingTable =>
{
string newCmd = sourceCmd;
GetReplaceGroups(operation, absTableName, aShardingTable).ForEach(aReplace =>
{
newCmd = newCmd.Replace(
sqlGenerationHelper.DelimitIdentifier(aReplace.sourceName),
sqlGenerationHelper.DelimitIdentifier(aReplace.targetName));
});
if (newCmd.Contains("EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE'"))
{
newCmd=newCmd.Replace($"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{absTableName}'", $"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{aShardingTable}'");
}
resList.Add(newCmd);
});
}
return resList;
string BuildPattern(string absTableName)
{
return string.Format("^({0})$|^({0}_.*?)$|^(.*?_{0}_.*?)$|^(.*?_{0})$", absTableName);
}
}
private static (MigrationResult migrationResult,List<string>) BuildDataSourceShardingCmds(IShardingRuntimeContext shardingRuntimeContext,string defaultDataSourceName,string dataSourceName,MigrationOperation operation, string sourceCmd, ISqlGenerationHelper sqlGenerationHelper)
private static (MigrationResult migrationResult, List<string>) BuildDataSourceShardingCmds(
IShardingRuntimeContext shardingRuntimeContext, string defaultDataSourceName, string dataSourceName,
MigrationOperation operation, string sourceCmd, ISqlGenerationHelper sqlGenerationHelper)
{
//所有MigrationOperation定义
//https://github.com/dotnet/efcore/tree/b970bf29a46521f40862a01db9e276e6448d3cb0/src/EFCore.Relational/Migrations/Operations
@ -143,7 +94,9 @@ namespace ShardingCore.Helpers
var entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager();
var tableRouteManager = shardingRuntimeContext.GetTableRouteManager();
var tableRoutes = tableRouteManager.GetRoutes();
var existsShardingTables = tableRoutes.ToDictionary(o => o.EntityMetadata.LogicTableName, o => o.GetTails().Select(p=>$"{o.EntityMetadata.LogicTableName}{o.EntityMetadata.TableSeparator}{p}").ToList());
var existsShardingTables = tableRoutes.ToDictionary(o => o.EntityMetadata.LogicTableName,
o => o.GetTails().Select(p => $"{o.EntityMetadata.LogicTableName}{o.EntityMetadata.TableSeparator}{p}")
.ToList());
//Dictionary<string, List<string>> _existsShardingTables
// = Cache.ServiceProvider.GetService<ShardingContainer>().ExistsShardingTables;
List<string> resList = new List<string>();
@ -153,7 +106,7 @@ namespace ShardingCore.Helpers
string tableName = operation.GetPropertyValue("Table") as string;
string pattern = string.Format("^({0})$|^({0}_.*?)$|^(.*?_{0}_.*?)$|^(.*?_{0})$", absTableName);
Func<KeyValuePair<string, List<string>>, bool> where = x =>
existsShardingTables.Any(y =>x.Key==y.Key&& Regex.IsMatch(name, BuildPattern(y.Key)));
existsShardingTables.Any(y => x.Key == y.Key && Regex.IsMatch(name, BuildPattern(y.Key)));
if (!string.IsNullOrWhiteSpace(tableName))
{
@ -163,7 +116,7 @@ namespace ShardingCore.Helpers
{
if (existsShardingTables.Any(x => where(x)))
{
absTableName = existsShardingTables.Where(x => where(x)).FirstOrDefault().Key;
absTableName = existsShardingTables.FirstOrDefault(x => where(x)).Key;
}
else
{
@ -176,33 +129,32 @@ namespace ShardingCore.Helpers
if (entityMetadata != null)
{
migrationResult.CommandType = MigrationCommandTypeEnum.TableCommand;
bool isShardingDataSource =entityMetadata.IsShardingDataSource();
bool isShardingDataSource = entityMetadata.IsShardingDataSource();
if (isShardingDataSource)
{
var virtualDataSourceRoute = dataSourceRouteManager.GetRoute(entityMetadata.EntityType);
isShardingDataSource = virtualDataSourceRoute.GetAllDataSourceNames().Contains(dataSourceName);
if (isShardingDataSource)
{
migrationResult.InDataSource = true;
}
else
{
migrationResult.InDataSource = false;
}
}
else
{
migrationResult.InDataSource = defaultDataSourceName==dataSourceName;
migrationResult.InDataSource = defaultDataSourceName == dataSourceName;
}
//分表
if (migrationResult.InDataSource&&!string.IsNullOrWhiteSpace(absTableName) && existsShardingTables.ContainsKey(absTableName))
if (migrationResult.InDataSource && !string.IsNullOrWhiteSpace(absTableName) &&
existsShardingTables.ContainsKey(absTableName))
{
var shardings = existsShardingTables[absTableName];
shardings.ForEach(aShardingTable =>
{
@ -213,22 +165,27 @@ namespace ShardingCore.Helpers
sqlGenerationHelper.DelimitIdentifier(aReplace.sourceName),
sqlGenerationHelper.DelimitIdentifier(aReplace.targetName));
});
if (newCmd.Contains("EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE'"))
if (newCmd.Contains(
"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE'"))
{
newCmd=newCmd.Replace($"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{absTableName}'", $"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{aShardingTable}'");
newCmd = newCmd.Replace(
$"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{absTableName}'",
$"EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE', N'{aShardingTable}'");
}
resList.Add(newCmd);
});
}
}
return (migrationResult,resList);
return (migrationResult, resList);
string BuildPattern(string absTableName)
{
return string.Format("^({0})$|^({0}_.*?)$|^(.*?_{0}_.*?)$|^(.*?_{0})$", absTableName);
}
}
private static List<(string sourceName, string targetName)> GetReplaceGroups(
MigrationOperation operation, string sourceTableName, string targetTableName)
{
@ -243,7 +200,11 @@ namespace ShardingCore.Helpers
{
if (!(operation is ColumnOperation columnOperation))
{
string[] patterns = new string[] { $"^()({sourceTableName})()$", $"^()({sourceTableName})(_.*?)$", $"^(.*?_)({sourceTableName})(_.*?)$", $"^(.*?_)({sourceTableName})()$" };
string[] patterns = new string[]
{
$"^()({sourceTableName})()$", $"^()({sourceTableName})(_.*?)$",
$"^(.*?_)({sourceTableName})(_.*?)$", $"^(.*?_)({sourceTableName})()$"
};
foreach (var aPattern in patterns)
{
if (Regex.IsMatch(name, aPattern))
@ -255,6 +216,7 @@ namespace ShardingCore.Helpers
}
}
}
Func<PropertyInfo, bool> listPropertyWhere = x =>
x.PropertyType.IsGenericType
&& x.PropertyType.GetGenericTypeDefinition() == typeof(List<>)
@ -280,7 +242,8 @@ namespace ShardingCore.Helpers
{
foreach (var aValue in (IEnumerable)propertyValue)
{
resList.AddRange(GetReplaceGroups((MigrationOperation)aValue, sourceTableName, targetTableName));
resList.AddRange(GetReplaceGroups((MigrationOperation)aValue, sourceTableName,
targetTableName));
}
}
});
@ -288,4 +251,4 @@ namespace ShardingCore.Helpers
return resList;
}
}
}
}

View File

@ -1,38 +0,0 @@
//using System;
//using System.Collections.Generic;
//using System.Data.Common;
//using System.Text;
//using Microsoft.EntityFrameworkCore;
//using ShardingCore.Sharding.Abstractions;
///*
//* @Author: xjm
//* @Description:
//* @Date: 2021/8/20 11:34:55
//* @Ver: 1.0
//* @Email: 326308290@qq.com
//*/
//namespace ShardingCore
//{
// /// <summary>
// /// 分片db context配置构造配置
// /// </summary>
// /// <typeparam name="TShardingDbContext"></typeparam>
// public interface IShardingDbContextOptionsBuilderConfig<TShardingDbContext> where TShardingDbContext:DbContext,IShardingDbContext
// {
// /// <summary>
// /// 如何根据connectionString 配置 DbContextOptionsBuilder
// /// </summary>
// /// <param name="connectionString"></param>
// /// <param name="dbContextOptionsBuilder"></param>
// /// <returns></returns>
// DbContextOptionsBuilder UseDbContextOptionsBuilder(string connectionString, DbContextOptionsBuilder dbContextOptionsBuilder);
// /// <summary>
// /// 如何根据dbConnection 配置DbContextOptionsBuilder
// /// </summary>
// /// <param name="dbConnection"></param>
// /// <param name="dbContextOptionsBuilder"></param>
// /// <returns></returns>
// DbContextOptionsBuilder UseDbContextOptionsBuilder(DbConnection dbConnection, DbContextOptionsBuilder dbContextOptionsBuilder);
// }
//}

View File

@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ShardingCore.Logger;
namespace ShardingCore.Jobs
{

View File

@ -1,52 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Text;
using System.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace ShardingCore.Logger
{
/// <summary>
///
/// </summary>
/// Author: xjm
/// Created: 2022/5/18 10:02:25
/// Email: 326308290@qq.com
public sealed class ShardingLoggerFactory
{
static ILoggerFactory _defaultFactory;
static ILoggerFactory NewDefaultFactory()
{
var f = new NullLoggerFactory();
return f;
}
/// <summary>
/// Gets or sets the default factory.
/// </summary>
public static ILoggerFactory DefaultFactory
{
get
{
ILoggerFactory factory = Volatile.Read(ref _defaultFactory);
if (factory == null)
{
factory = NewDefaultFactory();
ILoggerFactory current = Interlocked.CompareExchange(ref _defaultFactory, factory, null);
if (current != null)
{
return current;
}
}
return factory;
}
set => Volatile.Write(ref _defaultFactory, value);
}
public static ILogger<T> CreateLogger<T>() => DefaultFactory.CreateLogger<T>();
public static ILogger CreateLogger(string categoryName) => DefaultFactory.CreateLogger(categoryName);
}
}
// using System;
// using System.Collections.Generic;
// using System.Diagnostics.Contracts;
// using System.Text;
// using System.Threading;
// using Microsoft.Extensions.Logging;
// using Microsoft.Extensions.Logging.Abstractions;
//
// namespace ShardingCore.Logger
// {
// /// <summary>
// ///
// /// </summary>
// /// Author: xjm
// /// Created: 2022/5/18 10:02:25
// /// Email: 326308290@qq.com
// public sealed class ShardingLoggerFactory
// {
// static ILoggerFactory _defaultFactory;
//
//
// static ILoggerFactory NewDefaultFactory()
// {
// var f = new NullLoggerFactory();
// return f;
// }
//
// /// <summary>
// /// Gets or sets the default factory.
// /// </summary>
// public static ILoggerFactory DefaultFactory
// {
// get
// {
// ILoggerFactory factory = Volatile.Read(ref _defaultFactory);
// if (factory == null)
// {
// factory = NewDefaultFactory();
// ILoggerFactory current = Interlocked.CompareExchange(ref _defaultFactory, factory, null);
// if (current != null)
// {
// return current;
// }
// }
// return factory;
// }
// set => Volatile.Write(ref _defaultFactory, value);
// }
// public static ILogger<T> CreateLogger<T>() => DefaultFactory.CreateLogger<T>();
// public static ILogger CreateLogger(string categoryName) => DefaultFactory.CreateLogger(categoryName);
// }
// }

View File

@ -18,7 +18,7 @@ using ShardingCore.Core.RuntimeContexts;
using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Infrastructures;
using ShardingCore.Logger;
using ShardingCore.Sharding.Abstractions;
namespace ShardingCore.Sharding.ShardingDbContextExecutors

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ShardingCore.Core.QueryRouteManagers.Abstractions;
using ShardingCore.Extensions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Parsers.Abstractions;
using ShardingCore.Sharding.ShardingExecutors.Abstractions;
using ShardingCore.Sharding.Visitors.ShardingExtractParameters;

View File

@ -14,7 +14,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ShardingCore.Core;
using ShardingCore.Extensions.InternalExtensions;
using ShardingCore.Logger;
using ShardingCore.Sharding.MergeEngines;
#if EFCORE2
using Microsoft.EntityFrameworkCore.Internal;

View File

@ -11,7 +11,7 @@ using System.Linq;
using System.Linq.Expressions;
using ShardingCore.Core;
using ShardingCore.Extensions.InternalExtensions;
using ShardingCore.Logger;
using ShardingCore.Sharding.Parsers.Abstractions;
namespace ShardingCore.Sharding.ShardingExecutors

View File

@ -70,6 +70,7 @@ namespace ShardingCore
{
return Build(appServiceProvider, appServiceProvider?.GetService<ILoggerFactory>());
}
public IShardingRuntimeContext Build(IServiceProvider appServiceProvider, ILoggerFactory loggerFactory)
{
var shardingRuntimeContext = new ShardingRuntimeContext();

View File

@ -13,7 +13,6 @@ using System.Threading;
using ShardingCore.Core.DbContextCreator;
using ShardingCore.Core.ServiceProviders;
using ShardingCore.Core.ShardingConfigurations;
using ShardingCore.Logger;
using ShardingCore.Sharding;
namespace ShardingCore.TableCreator

View File

@ -17,7 +17,7 @@ using ShardingCore.Core.VirtualRoutes.Abstractions;
using ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions;
using ShardingCore.Extensions;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Logger;
using ShardingCore.TableCreator;
namespace ShardingCore.VirtualRoutes.Abstractions