38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using SqlSugar;
|
|
using SqlSugar.IOC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using VideoAnalysisCore.Model;
|
|
|
|
namespace VideoAnalysisCore.Common
|
|
{
|
|
public class Repository<T> : SimpleClient<T> where T : class, new()
|
|
{
|
|
readonly Dictionary<Type, object?> CID= new Dictionary<Type, object?>();
|
|
public Repository()
|
|
{
|
|
SwitchConnection();
|
|
}
|
|
public void SwitchConnection()
|
|
{
|
|
var t = typeof(T);
|
|
if (CID.ContainsKey(t))
|
|
{
|
|
base.Context = DbScoped.Sugar.GetConnectionScope(CID[t]);
|
|
return;
|
|
}
|
|
var c = t.GetCustomAttribute<TenantAttribute>();
|
|
if (!CID.ContainsKey(typeof(T)))
|
|
CID.Add(typeof(T), c?.configId);
|
|
base.Context = c != null
|
|
? DbScoped.Sugar.GetConnectionScope(c.configId)
|
|
: DbScoped.Sugar;
|
|
}
|
|
}
|
|
}
|