using HuanMeng.DotNetCore.MultiTenant; using HuanMeng.DotNetCore.MultiTenant.Contract; using HuanMeng.MiaoYu.Code.AppExtend; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HuanMeng.MiaoYu.Code.MultiTenantUtil { /// /// 多租户中间件 /// public class MiaoYuMultiTenantTenantMiddleware { private readonly RequestDelegate _next; public MiaoYuMultiTenantTenantMiddleware(RequestDelegate next) { _next = next; } /// /// 根据HttpContext获取并设置当前租户ID /// /// /// /// /// public virtual async Task Invoke(HttpContext context, IServiceProvider _serviceProvider, ITenantInfo tenantInfo, AppConfig appConfig ) { if (tenantInfo == null) { tenantInfo = new TenantInfo(); } var host = context.Request.Host.Host; var app = AppConfigurationExtend.GetAppConfig(host); app.ToAppConfig(appConfig).ToITenantInfo(tenantInfo); //var _ten = miaoYuMultiTenantConfig.GetMultiTenantCfgDefault(); //tenantInfo.ConnectionString = _ten.ConnectionString; //tenantInfo.Identifier = _ten.Identifier; //tenantInfo.TenantId = _ten.TenantId; //tenantInfo.Name = _ten.Name; await _next.Invoke(context); } } }