🔄refactor: 替换EF为SqlSugar

This commit is contained in:
yubaolee
2026-06-27 23:08:53 +08:00
parent 5fdf58a0c6
commit 252abfe5be
2 changed files with 41 additions and 8 deletions

View File

@@ -18,6 +18,10 @@ using Infrastructure;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using SqlSugar;
using Infrastructure.Extensions.AutofacManager;
using Infrastructure.Utilities;
using Microsoft.AspNetCore.Http;
namespace OpenAuth.App
{
@@ -29,15 +33,28 @@ namespace OpenAuth.App
{
private SystemAuthStrategy _systemAuth;
private NormalAuthStrategy _normalAuthStrategy;
private readonly IUnitWork<OpenAuthDBContext> _unitWork;
protected ISqlSugarClient SugarClient;
public AuthContextFactory(SystemAuthStrategy sysStrategy
, NormalAuthStrategy normalAuthStrategy
, IUnitWork<OpenAuthDBContext> unitWork)
, ISqlSugarClient client)
{
_systemAuth = sysStrategy;
_normalAuthStrategy = normalAuthStrategy;
_unitWork = unitWork;
string tenantId = Define.DEFAULT_TENANT_ID;
var httpContextAccessor = AutofacContainerModule.GetService<IHttpContextAccessor>();
if (httpContextAccessor != null)
{
tenantId = httpContextAccessor.GetTenantId();
}
if(tenantId != Define.DEFAULT_TENANT_ID) //如果不是默认租户则使用租户id获取连接
{
client = client.AsTenant().GetConnection(tenantId);
}
SugarClient = client;
}
public AuthStrategyContext GetAuthStrategyContext(string username)
@@ -52,7 +69,7 @@ namespace OpenAuth.App
else
{
service = _normalAuthStrategy;
service.User = _unitWork.FirstOrDefault<SysUser>(u => u.Account == username);
service.User = SugarClient.Queryable<SysUser>().First(u => u.Account == username);
}
return new AuthStrategyContext(service);