48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using CloudGaming.Core.AgileConfig;
|
|
using CloudGaming.Shared.Admin.ApplicationServices;
|
|
|
|
using HZY.Framework.DependencyInjection.Attributes;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CloudGaming.Code.DataBaseModel.MiddlewareExtend;
|
|
|
|
public class AppConfigMiddleware(RequestDelegate next, AppConfigTenant appConfigTenant)
|
|
{
|
|
|
|
[Autowired]
|
|
public virtual AppConfig appConfig { get; set; }
|
|
[Autowired]
|
|
public virtual IAccountService AccountService { get; set; }
|
|
|
|
public async Task Invoke(HttpContext context)
|
|
{
|
|
var host = context.Request.Host.Host;
|
|
var account = AccountService.GetAccountContext();
|
|
if (appConfigTenant.Tenants != null && appConfigTenant.Tenants.Count > 0)
|
|
{
|
|
if (account != null && account.SysOrganization != null && account.SysOrganization.TenantId != Guid.Empty)
|
|
{
|
|
|
|
appConfigTenant.Tenants.GetTenantIdAppConfig(account.SysOrganization.TenantId ?? Guid.Empty, appConfig);
|
|
}
|
|
else
|
|
{
|
|
appConfigTenant.Tenants.GetHostOrDefaultAppConfig(host, appConfig);
|
|
}
|
|
if (string.IsNullOrEmpty(appConfig.Name))
|
|
{
|
|
appConfigTenant.Tenants.GetHostOrDefaultAppConfig(host, appConfig);
|
|
}
|
|
}
|
|
|
|
await next(context);
|
|
}
|
|
}
|