优化设置默认如果是启用了多配置的情况下

This commit is contained in:
xuejiaming 2022-01-07 10:54:28 +08:00
parent f2febbae4e
commit 2b99353bc5
6 changed files with 18 additions and 29 deletions

View File

@ -1,30 +1,13 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using EFCore.BulkExtensions;
using BenchmarkDotNet.Attributes;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using ShardingCore;
using ShardingCore.Bootstrapers;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
using ShardingCore.Core.VirtualDatabase.VirtualTables;
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.RouteRuleEngine;
using ShardingCore.Core.VirtualRoutes.TableRoutes;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
using ShardingCore.Core.VirtualTables;
using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Sharding;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.Sharding.ShardingDbContextExecutors;
using ShardingCore6x.NoShardingDbContexts;
using ShardingCore6x.ShardingDbContexts;
using System.Diagnostics;
namespace ShardingCore6x

View File

@ -1,9 +1,9 @@
:start
::定义版本
set EFCORE2=2.4.0.01-preview2
set EFCORE3=3.4.0.01-preview2
set EFCORE5=5.4.0.01-preview2
set EFCORE6=6.4.0.01-preview2
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
::删除所有bin与obj下的文件
@echo off

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Sample.MultiConfig.Domain.Entities;
using ShardingCore.Core.VirtualDatabase.VirtualTables;
namespace Sample.MultiConfig.Controllers
{
@ -9,10 +10,12 @@ namespace Sample.MultiConfig.Controllers
public class TestController:ControllerBase
{
private readonly MultiConfigDbContext _multiConfigDbContext;
private readonly IVirtualTableManager<MultiConfigDbContext> _virtualTableManager;
public TestController(MultiConfigDbContext multiConfigDbContext)
public TestController(MultiConfigDbContext multiConfigDbContext,IVirtualTableManager<MultiConfigDbContext> virtualTableManager)
{
_multiConfigDbContext = multiConfigDbContext;
_virtualTableManager = virtualTableManager;
}
public async Task<IActionResult> Add()
{

View File

@ -99,9 +99,9 @@ namespace ShardingCore.Bootstrapers
using (_virtualDataSourceManager.CreateScope(configId))
{
//var dataSourceName = _virtualDataSource.DefaultDataSourceName;
using var context =
(DbContext)serviceScope.ServiceProvider.GetService(_shardingDbContextType);
foreach (var entity in context.Model.GetEntityTypes())
{
var entityType = entity.ClrType;

View File

@ -43,9 +43,9 @@ namespace ShardingCore.Core.ShardingConfigurations.ConfigBuilders
throw new ArgumentNullException(
$"{nameof(shardingGlobalConfigOptions.DefaultConnectionString)} plz call {nameof(ShardingConfigOptions<TShardingDbContext>.AddDefaultDataSource)}");
if (shardingGlobalConfigOptions.ConnectionStringConfigure is null)
if (shardingGlobalConfigOptions.ConnectionStringConfigure is null&& ShardingCoreConfigBuilder.ShardingEntityConfigOptions.ConnectionStringConfigure is null)
throw new ArgumentNullException($"plz call {nameof(shardingGlobalConfigOptions.UseShardingQuery)}");
if (shardingGlobalConfigOptions.ConnectionConfigure is null)
if (shardingGlobalConfigOptions.ConnectionConfigure is null && ShardingCoreConfigBuilder.ShardingEntityConfigOptions.ConnectionConfigure is null)
throw new ArgumentNullException(
$"plz call {nameof(shardingGlobalConfigOptions.UseShardingTransaction)}");

View File

@ -140,8 +140,11 @@ namespace ShardingCore.Core.VirtualDatabase.VirtualDataSources
if (IsMultiShardingConfiguration && ShardingConfigurationStrategy == ShardingConfigurationStrategyEnum.ReturnHighPriority)
{
var maxShardingConfiguration = _virtualDataSources.Values.OrderByDescending(o => o.Priority).FirstOrDefault();
_defaultVirtualDataSource = maxShardingConfiguration;
if (maxShardingConfiguration.ConfigId != _defaultConfigId)
{
_defaultConfigId = maxShardingConfiguration.ConfigId;
_defaultVirtualDataSource = maxShardingConfiguration;
}
}
}