mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-01 10:10:16 +08:00
Update ScopedClient
This commit is contained in:
parent
2b04188ddd
commit
5c89adc609
@ -10,29 +10,29 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class ScopedClient : ISqlSugarClient, ITenant
|
public class ScopedClient : ISqlSugarClient, ITenant
|
||||||
{
|
{
|
||||||
private SqlSugarClient db;
|
private List<ConnectionConfig> _configs;
|
||||||
private Action<SqlSugarClient> configAction;
|
private Action<SqlSugarClient> _configAction;
|
||||||
private ScopedClient()
|
private ScopedClient()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public ScopedClient(ConnectionConfig config)
|
public ScopedClient(ConnectionConfig config)
|
||||||
{
|
{
|
||||||
this.db = new SqlSugarClient(config);
|
_configs=new List<ConnectionConfig>() { config};
|
||||||
}
|
}
|
||||||
public ScopedClient(List<ConnectionConfig> configs)
|
public ScopedClient(List<ConnectionConfig> configs)
|
||||||
{
|
{
|
||||||
this.db = new SqlSugarClient(configs);
|
_configs = configs;
|
||||||
}
|
}
|
||||||
public ScopedClient(ConnectionConfig config, Action<SqlSugarClient> configAction)
|
public ScopedClient(ConnectionConfig config, Action<SqlSugarClient> configAction)
|
||||||
{
|
{
|
||||||
this.db = new SqlSugarClient(config);
|
_configs = new List<ConnectionConfig>() { config };
|
||||||
this.configAction = configAction;
|
this._configAction = configAction;
|
||||||
}
|
}
|
||||||
public ScopedClient(List<ConnectionConfig> configs, Action<SqlSugarClient> configAction)
|
public ScopedClient(List<ConnectionConfig> configs, Action<SqlSugarClient> configAction)
|
||||||
{
|
{
|
||||||
this.db = new SqlSugarClient(configs);
|
_configs = configs;
|
||||||
this.configAction = configAction;
|
this._configAction = configAction;
|
||||||
}
|
}
|
||||||
//public ScopedClient(SqlSugarClient context,Action<SqlSugarClient> configAction)
|
//public ScopedClient(SqlSugarClient context,Action<SqlSugarClient> configAction)
|
||||||
//{
|
//{
|
||||||
@ -44,7 +44,7 @@ namespace SqlSugar
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
SqlSugarClient result = null;
|
SqlSugarClient result = null;
|
||||||
var key = db.GetHashCode().ToString();
|
var key = _configs.GetHashCode().ToString();
|
||||||
StackTrace st = new StackTrace(true);
|
StackTrace st = new StackTrace(true);
|
||||||
var methods = st.GetFrames();
|
var methods = st.GetFrames();
|
||||||
var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
|
var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
|
||||||
@ -65,11 +65,11 @@ namespace SqlSugar
|
|||||||
SqlSugarClient result = CallContextAsync<SqlSugarClient>.GetData(key);
|
SqlSugarClient result = CallContextAsync<SqlSugarClient>.GetData(key);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
CallContextAsync<SqlSugarClient>.SetData(key, new SqlSugarClient(db._allConfigs));
|
CallContextAsync<SqlSugarClient>.SetData(key, new SqlSugarClient(_configs));
|
||||||
result = CallContextAsync<SqlSugarClient>.GetData(key);
|
result = CallContextAsync<SqlSugarClient>.GetData(key);
|
||||||
if (this.configAction != null)
|
if (this._configAction != null)
|
||||||
{
|
{
|
||||||
this.configAction(result);
|
this._configAction(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +81,11 @@ namespace SqlSugar
|
|||||||
SqlSugarClient result = CallContextThread<SqlSugarClient>.GetData(key);
|
SqlSugarClient result = CallContextThread<SqlSugarClient>.GetData(key);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
CallContextThread<SqlSugarClient>.SetData(key, new SqlSugarClient(db._allConfigs));
|
CallContextThread<SqlSugarClient>.SetData(key, new SqlSugarClient(_configs));
|
||||||
result = CallContextThread<SqlSugarClient>.GetData(key);
|
result = CallContextThread<SqlSugarClient>.GetData(key);
|
||||||
if (this.configAction != null)
|
if (this._configAction != null)
|
||||||
{
|
{
|
||||||
this.configAction(result);
|
this._configAction(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user