diff --git a/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs b/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs index cc25ddc8..85f78e6c 100644 --- a/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs +++ b/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs @@ -61,7 +61,7 @@ namespace ShardingCore.Bootstrapers private readonly IEntityMetadataManager _entityMetadataManager; private readonly IShardingTableCreator _tableCreator; private readonly IParallelTableManager _parallelTableManager; - private readonly IDefaultDataSourceInitializer _dataSourceInitializer; + private readonly IDataSourceInitializer _dataSourceInitializer; private readonly ILogger> _logger; public ShardingDbContextBootstrapper(IShardingConfigOption shardingConfigOption) @@ -73,7 +73,7 @@ namespace ShardingCore.Bootstrapers _tableCreator = ShardingContainer.GetService>(); _virtualDataSource= ShardingContainer.GetService>(); _parallelTableManager = ShardingContainer.GetService>(); - _dataSourceInitializer = ShardingContainer.GetService>(); + _dataSourceInitializer = ShardingContainer.GetService>(); _logger = ShardingContainer.GetService>>(); } /// diff --git a/src/ShardingCore/DIExtension.cs b/src/ShardingCore/DIExtension.cs index 30a377c8..c80f5204 100644 --- a/src/ShardingCore/DIExtension.cs +++ b/src/ShardingCore/DIExtension.cs @@ -90,7 +90,7 @@ namespace ShardingCore 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(IStreamMergeContextFactory<>),typeof(StreamMergeContextFactory<>)); services.TryAddSingleton(typeof(IShardingTableCreator<>),typeof(ShardingTableCreator<>)); diff --git a/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs b/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs index 64f85508..f4def3b7 100644 --- a/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs +++ b/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs @@ -25,26 +25,22 @@ using ShardingCore.TableExists.Abstractions; namespace ShardingCore.DynamicDataSources { - public interface IDefaultDataSourceInitializer where TShardingDbContext : DbContext, IShardingDbContext - { - void InitConfigure(string dataSourceName, string connectionString); - } - public class DefaultDataSourceInitializer : IDefaultDataSourceInitializer where TShardingDbContext : DbContext, IShardingDbContext + public class DataSourceInitializer : IDataSourceInitializer where TShardingDbContext : DbContext, IShardingDbContext { private readonly IRouteTailFactory _routeTailFactory; private readonly IVirtualTableManager _virtualTableManager; private readonly IVirtualDataSource _virtualDataSource; private readonly IEntityMetadataManager _entityMetadataManager; private readonly IShardingTableCreator _tableCreator; - private readonly ILogger> _logger; + private readonly ILogger> _logger; private readonly IShardingConfigOption _shardingConfigOption; - public DefaultDataSourceInitializer(IEnumerable shardingConfigOptions, + public DataSourceInitializer(IEnumerable shardingConfigOptions, IRouteTailFactory routeTailFactory, IVirtualTableManager virtualTableManager, IEntityMetadataManager entityMetadataManager, IShardingTableCreator shardingTableCreator, IVirtualDataSource virtualDataSource, - ILogger> logger) + ILogger> logger) { _shardingConfigOption = shardingConfigOptions.FirstOrDefault(o => o.ShardingDbContextType == typeof(TShardingDbContext)) ?? throw new ArgumentNullException($"{nameof(IShardingConfigOption)} cant been registered {typeof(TShardingDbContext)}"); diff --git a/src/ShardingCore/DynamicDataSources/DynamicDataSourceHelper.cs b/src/ShardingCore/DynamicDataSources/DynamicDataSourceHelper.cs index dd10a2ec..b66bd7ee 100644 --- a/src/ShardingCore/DynamicDataSources/DynamicDataSourceHelper.cs +++ b/src/ShardingCore/DynamicDataSources/DynamicDataSourceHelper.cs @@ -13,7 +13,7 @@ namespace ShardingCore.DynamicDataSources public static void DynamicAppendDataSource(string dataSourceName, string connectionString) where TShardingDbContext:DbContext,IShardingDbContext { - var defaultDataSourceInitializer = ShardingContainer.GetService>(); + var defaultDataSourceInitializer = ShardingContainer.GetService>(); defaultDataSourceInitializer.InitConfigure(dataSourceName, connectionString); } diff --git a/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs b/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs new file mode 100644 index 00000000..d03a9c4b --- /dev/null +++ b/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs @@ -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 where TShardingDbContext : DbContext, IShardingDbContext + { + void InitConfigure(string dataSourceName, string connectionString); + } +}