支持多租户数据库
This commit is contained in:
parent
a879a5d585
commit
8e2231df90
|
@ -2,6 +2,7 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Falcon.SugarApi.DatabaseManager
|
namespace Falcon.SugarApi.DatabaseManager
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,17 @@ namespace Falcon.SugarApi.DatabaseManager
|
||||||
this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
|
this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
|
||||||
ConfigureExternalServices(this.CurrentConnectionConfig);
|
ConfigureExternalServices(this.CurrentConnectionConfig);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 使用服务提供程序和配置集合初始化数据库上下文
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="service">服务提供程序</param>
|
||||||
|
/// <param name="configs">数据库上下文配置集合</param>
|
||||||
|
public DbContextBase(IServiceProvider service,params ConnectionConfig[] configs) : base(configs.ToList()) {
|
||||||
|
this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
|
||||||
|
foreach(var c in configs) {
|
||||||
|
ConfigureExternalServices(this.GetConnection(c.ConfigId).CurrentConnectionConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void ConfigureExternalServices(ConnectionConfig config) {
|
private static void ConfigureExternalServices(ConnectionConfig config) {
|
||||||
config.ConfigureExternalServices ??= new ConfigureExternalServices();
|
config.ConfigureExternalServices ??= new ConfigureExternalServices();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user