修改数据源初始化器接口名称

This commit is contained in:
xuejiaming 2021-12-13 09:18:28 +08:00
parent fb61eb4bcc
commit cb836a25e9
5 changed files with 23 additions and 12 deletions

View File

@ -61,7 +61,7 @@ namespace ShardingCore.Bootstrapers
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager; private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
private readonly IShardingTableCreator<TShardingDbContext> _tableCreator; private readonly IShardingTableCreator<TShardingDbContext> _tableCreator;
private readonly IParallelTableManager<TShardingDbContext> _parallelTableManager; private readonly IParallelTableManager<TShardingDbContext> _parallelTableManager;
private readonly IDefaultDataSourceInitializer<TShardingDbContext> _dataSourceInitializer; private readonly IDataSourceInitializer<TShardingDbContext> _dataSourceInitializer;
private readonly ILogger<ShardingDbContextBootstrapper<TShardingDbContext>> _logger; private readonly ILogger<ShardingDbContextBootstrapper<TShardingDbContext>> _logger;
public ShardingDbContextBootstrapper(IShardingConfigOption shardingConfigOption) public ShardingDbContextBootstrapper(IShardingConfigOption shardingConfigOption)
@ -73,7 +73,7 @@ namespace ShardingCore.Bootstrapers
_tableCreator = ShardingContainer.GetService<IShardingTableCreator<TShardingDbContext>>(); _tableCreator = ShardingContainer.GetService<IShardingTableCreator<TShardingDbContext>>();
_virtualDataSource= ShardingContainer.GetService<IVirtualDataSource<TShardingDbContext>>(); _virtualDataSource= ShardingContainer.GetService<IVirtualDataSource<TShardingDbContext>>();
_parallelTableManager = ShardingContainer.GetService<IParallelTableManager<TShardingDbContext>>(); _parallelTableManager = ShardingContainer.GetService<IParallelTableManager<TShardingDbContext>>();
_dataSourceInitializer = ShardingContainer.GetService<IDefaultDataSourceInitializer<TShardingDbContext>>(); _dataSourceInitializer = ShardingContainer.GetService<IDataSourceInitializer<TShardingDbContext>>();
_logger = ShardingContainer.GetService<ILogger<ShardingDbContextBootstrapper<TShardingDbContext>>>(); _logger = ShardingContainer.GetService<ILogger<ShardingDbContextBootstrapper<TShardingDbContext>>>();
} }
/// <summary> /// <summary>

View File

@ -90,7 +90,7 @@ namespace ShardingCore
services.TryAddSingleton(typeof(IShardingDbContextCreatorConfig<>),typeof(DefaultShardingDbContextCreatorConfig<>)); services.TryAddSingleton(typeof(IShardingDbContextCreatorConfig<>),typeof(DefaultShardingDbContextCreatorConfig<>));
services.TryAddSingleton(typeof(IDefaultDataSourceInitializer<>),typeof(DefaultDataSourceInitializer<>)); services.TryAddSingleton(typeof(IDataSourceInitializer<>),typeof(DataSourceInitializer<>));
services.TryAddSingleton(typeof(ITrackerManager<>),typeof(TrackerManager<>)); services.TryAddSingleton(typeof(ITrackerManager<>),typeof(TrackerManager<>));
services.TryAddSingleton(typeof(IStreamMergeContextFactory<>),typeof(StreamMergeContextFactory<>)); services.TryAddSingleton(typeof(IStreamMergeContextFactory<>),typeof(StreamMergeContextFactory<>));
services.TryAddSingleton(typeof(IShardingTableCreator<>),typeof(ShardingTableCreator<>)); services.TryAddSingleton(typeof(IShardingTableCreator<>),typeof(ShardingTableCreator<>));

View File

@ -25,26 +25,22 @@ using ShardingCore.TableExists.Abstractions;
namespace ShardingCore.DynamicDataSources namespace ShardingCore.DynamicDataSources
{ {
public interface IDefaultDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
{
void InitConfigure(string dataSourceName, string connectionString);
}
public class DefaultDataSourceInitializer<TShardingDbContext> : IDefaultDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext public class DataSourceInitializer<TShardingDbContext> : IDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
{ {
private readonly IRouteTailFactory _routeTailFactory; private readonly IRouteTailFactory _routeTailFactory;
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager; private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
private readonly IVirtualDataSource<TShardingDbContext> _virtualDataSource; private readonly IVirtualDataSource<TShardingDbContext> _virtualDataSource;
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager; private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
private readonly IShardingTableCreator<TShardingDbContext> _tableCreator; private readonly IShardingTableCreator<TShardingDbContext> _tableCreator;
private readonly ILogger<DefaultDataSourceInitializer<TShardingDbContext>> _logger; private readonly ILogger<DataSourceInitializer<TShardingDbContext>> _logger;
private readonly IShardingConfigOption _shardingConfigOption; private readonly IShardingConfigOption _shardingConfigOption;
public DefaultDataSourceInitializer(IEnumerable<IShardingConfigOption> shardingConfigOptions, public DataSourceInitializer(IEnumerable<IShardingConfigOption> shardingConfigOptions,
IRouteTailFactory routeTailFactory, IVirtualTableManager<TShardingDbContext> virtualTableManager, IRouteTailFactory routeTailFactory, IVirtualTableManager<TShardingDbContext> virtualTableManager,
IEntityMetadataManager<TShardingDbContext> entityMetadataManager, IEntityMetadataManager<TShardingDbContext> entityMetadataManager,
IShardingTableCreator<TShardingDbContext> shardingTableCreator, IShardingTableCreator<TShardingDbContext> shardingTableCreator,
IVirtualDataSource<TShardingDbContext> virtualDataSource, IVirtualDataSource<TShardingDbContext> virtualDataSource,
ILogger<DefaultDataSourceInitializer<TShardingDbContext>> logger) ILogger<DataSourceInitializer<TShardingDbContext>> logger)
{ {
_shardingConfigOption = _shardingConfigOption =
shardingConfigOptions.FirstOrDefault(o => o.ShardingDbContextType == typeof(TShardingDbContext)) ?? throw new ArgumentNullException($"{nameof(IShardingConfigOption)} cant been registered {typeof(TShardingDbContext)}"); shardingConfigOptions.FirstOrDefault(o => o.ShardingDbContextType == typeof(TShardingDbContext)) ?? throw new ArgumentNullException($"{nameof(IShardingConfigOption)} cant been registered {typeof(TShardingDbContext)}");

View File

@ -13,7 +13,7 @@ namespace ShardingCore.DynamicDataSources
public static void DynamicAppendDataSource<TShardingDbContext>(string dataSourceName, string connectionString) where TShardingDbContext:DbContext,IShardingDbContext public static void DynamicAppendDataSource<TShardingDbContext>(string dataSourceName, string connectionString) where TShardingDbContext:DbContext,IShardingDbContext
{ {
var defaultDataSourceInitializer = ShardingContainer.GetService<IDefaultDataSourceInitializer<TShardingDbContext>>(); var defaultDataSourceInitializer = ShardingContainer.GetService<IDataSourceInitializer<TShardingDbContext>>();
defaultDataSourceInitializer.InitConfigure(dataSourceName, connectionString); defaultDataSourceInitializer.InitConfigure(dataSourceName, connectionString);
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ShardingCore.Sharding.Abstractions;
namespace ShardingCore.DynamicDataSources
{
public interface IDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
{
void InitConfigure(string dataSourceName, string connectionString);
}
}