修改数据源初始化器接口名称
This commit is contained in:
parent
fb61eb4bcc
commit
cb836a25e9
|
@ -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>
|
||||||
|
|
|
@ -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<>));
|
||||||
|
|
|
@ -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)}");
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue