支持多租户数据库

This commit is contained in:
Falcon 2024-08-19 16:03:11 +08:00
parent a879a5d585
commit 8e2231df90

View File

@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using SqlSugar;
using System;
using System.Linq;
namespace Falcon.SugarApi.DatabaseManager
{
@ -24,6 +25,17 @@ namespace Falcon.SugarApi.DatabaseManager
this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger;
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) {
config.ConfigureExternalServices ??= new ConfigureExternalServices();