1212using ShardingCore . Core ;
1313using ShardingCore . Core . ModelCacheLockerProviders ;
1414using ShardingCore . Core . RuntimeContexts ;
15+ using ShardingCore . DynamicDataSources ;
1516using ShardingCore . EFCores ;
1617using ShardingCore . Extensions ;
1718using ShardingCore . Helpers ;
@@ -68,13 +69,13 @@ public void ConfigureServices(IServiceCollection services)
6869 // optionsBuilder(sp, builder);
6970 // });
7071 //
71-
72-
72+
73+
7374 services . AddShardingDbContext < DefaultShardingDbContext > ( )
74- . UseRouteConfig ( ( sp , o ) =>
75+ . UseRouteConfig ( ( sp , o ) =>
7576 {
7677 o . AddShardingTableRoute < DynamicTableRoute > ( ) ;
77- o . AddShardingTableRoute < SysUserLogByMonthRoute > ( ) ;
78+ o . AddShardingTableRoute < SysUserLogByMonthRoute > ( ) ;
7879 o . AddShardingTableRoute < SysUserModVirtualTableRoute > ( ) ;
7980 o . AddShardingDataSourceRoute < SysUserModVirtualDataSourceRoute > ( ) ;
8081 o . AddShardingTableRoute < TestModRoute > ( ) ;
@@ -85,7 +86,7 @@ public void ConfigureServices(IServiceCollection services)
8586 new ParallelTableComparerType ( typeof ( TestMod ) ) ,
8687 new ParallelTableComparerType ( typeof ( TestModItem ) ) ,
8788 } ) ) ;
88- } ) . UseConfig ( ( sp , o ) =>
89+ } ) . UseConfig ( ( sp , o ) =>
8990 {
9091 // var memoryCache = sp.ApplicationServiceProvider.GetRequiredService<IMemoryCache>();
9192 // o.UseExecutorDbContextConfigure(b =>
@@ -97,17 +98,17 @@ public void ConfigureServices(IServiceCollection services)
9798 o . CacheEntrySize = 1 ;
9899 o . CacheModelLockObjectSeconds = 10 ;
99100 o . CheckShardingKeyValueGenerated = false ;
100- var loggerFactory1 = sp . GetService < ILoggerFactory > ( ) ;
101+ var loggerFactory1 = sp . GetService < ILoggerFactory > ( ) ;
101102 var loggerFactory2 = sp . ApplicationServiceProvider . GetService < ILoggerFactory > ( ) ;
102103 // o.UseEntityFrameworkCoreProxies = true;
103- o . ThrowIfQueryRouteNotMatch = false ;
104+ o . ThrowIfQueryRouteNotMatch = false ;
104105 o . AutoUseWriteConnectionStringAfterWriteDb = true ;
105-
106+
106107 o . UseShardingQuery ( ( conStr , builder ) =>
107108 {
108109 builder . UseMySql ( conStr , new MySqlServerVersion ( new Version ( ) ) )
109110 . UseLoggerFactory ( loggerFactory1 )
110- . EnableSensitiveDataLogging ( ) ;
111+ . EnableSensitiveDataLogging ( ) ;
111112 //.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
112113 } ) ;
113114 o . UseShardingTransaction ( ( connection , builder ) =>
@@ -116,7 +117,7 @@ public void ConfigureServices(IServiceCollection services)
116117 . UseMySql ( connection , new MySqlServerVersion ( new Version ( ) ) )
117118 . UseLoggerFactory ( loggerFactory1 )
118119 . EnableSensitiveDataLogging ( ) ;
119- //.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
120+ //.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
120121 } ) ;
121122 o . AddDefaultDataSource ( "ds0" ,
122123 "server=127.0.0.1;port=3306;database=dbdbd0;userid=root;password=root;" ) ;
@@ -129,7 +130,8 @@ public void ConfigureServices(IServiceCollection services)
129130 {
130131 b . ReplaceService < IMigrationsSqlGenerator , ShardingMySqlMigrationsSqlGenerator > ( ) ;
131132 } ) ;
132- } ) . ReplaceService < IModelCacheLockerProvider , DicModelCacheLockerProvider > ( )
133+ } ) . ReplaceService < IModelCacheLockerProvider , DicModelCacheLockerProvider > ( )
134+ . ReplaceService < IDataSourceInitializer , DataSourceInitializer > ( )
133135 . AddShardingCore ( ) ;
134136 // services.AddDbContext<DefaultShardingDbContext>(ShardingCoreExtension
135137 // .UseMutliDefaultSharding<DefaultShardingDbContext>);
@@ -178,19 +180,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
178180 app . UseDeveloperExceptionPage ( ) ;
179181 }
180182 // app.ApplicationServices.UseAutoTryCompensateTable();
181-
183+
182184 // var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext>();
183185 // var entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager();
184186 // var entityMetadata = entityMetadataManager.TryGet<SysUserMod>();
185- using ( var scope = app . ApplicationServices . CreateScope ( ) )
186- {
187- var defaultShardingDbContext = scope . ServiceProvider . GetService < DefaultShardingDbContext > ( ) ;
188- // if (defaultShardingDbContext.Database.GetPendingMigrations().Any())
189- {
190- defaultShardingDbContext . Database . GenerateCreateScript ( ) ;
191- }
192- }
193- app . ApplicationServices . UseAutoTryCompensateTable ( ) ;
187+ // using (var scope = app.ApplicationServices.CreateScope())
188+ // {
189+ // var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>();
190+ // // if (defaultShardingDbContext.Database.GetPendingMigrations().Any())
191+ // {
192+ // defaultShardingDbContext.Database.GenerateCreateScript();
193+ // }
194+ // }
195+
196+ // app.ApplicationServices.UseAutoTryCompensateTable();
194197 // using (var scope = app.ApplicationServices.CreateScope())
195198 // {
196199 // var defaultShardingDbContext = scope.ServiceProvider.GetService<OtherDbContext>();
0 commit comments