2021-03-05 16:55:52 +08:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-01-26 10:18:49 +08:00
|
|
|
using ShardingCore.DbContexts.ShardingDbContexts;
|
|
|
|
|
|
|
|
namespace ShardingCore.DbContexts
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* @Author: xjm
|
|
|
|
* @Description:
|
|
|
|
* @Date: Thursday, 24 December 2020 08:22:48
|
|
|
|
* @Email: 326308290@qq.com
|
|
|
|
*/
|
|
|
|
public class ShardingDbContextFactory:IShardingDbContextFactory
|
|
|
|
{
|
2021-03-05 16:55:52 +08:00
|
|
|
private readonly IShardingCoreOptions _shardingCoreOptions;
|
|
|
|
|
|
|
|
public ShardingDbContextFactory(IShardingCoreOptions shardingCoreOptions)
|
|
|
|
{
|
|
|
|
_shardingCoreOptions = shardingCoreOptions;
|
|
|
|
}
|
|
|
|
public DbContext Create(string connectKey, ShardingDbContextOptions shardingDbContextOptions)
|
2021-01-26 10:18:49 +08:00
|
|
|
{
|
2021-03-05 16:55:52 +08:00
|
|
|
var shardingConfigEntry = _shardingCoreOptions.GetShardingConfig(connectKey);
|
|
|
|
return shardingConfigEntry.Creator(shardingDbContextOptions);
|
2021-01-26 10:18:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|