namespace Admin.NET.Core;
/// <summary>
/// SqlSugar 实体仓储
/// </summary>
/// <typeparam name="T"></typeparam>
public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
{
protected ITenant iTenant = null;
public SqlSugarRepository()
{
var host = App.HttpContext?.Request.Host.Value.ToString();
if(string.IsNullOrEmpty(host))
{
host = "";
}
if(host.Contains("localhost") || host.Contains("127.0.0.1"))
{
base.Context = App.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope(SqlSugarConst.MainConfigId);
return;
}
else if (host.Contains("npsy.wxy.work"))
{
base.Context = App.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("npsy");
return;
}
else if (host.Contains("npjj.wxy.work"))
{
base.Context = App.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("npjj");
return;
}
else if (host.Contains("19.wxy.work"))
{
base.Context = App.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("npjx");
return;
}
else
{
base.Context = App.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope(SqlSugarConst.MainConfigId);
return;
}
}
}
标签:return,Admin,App,Contains,域名,host,base,Net,GetRequiredService
From: https://www.cnblogs.com/shiningrise/p/18423045