- 优化 BaseDbProvider、AdoNetExtensions 内部定义;

This commit is contained in:
2881099
2021-03-03 11:46:03 +08:00
parent 1398514a96
commit 054fc4c805
4 changed files with 45 additions and 10 deletions

View File

@ -9,14 +9,15 @@ namespace FreeSql
{
#region Ado.net Dapper
static Dictionary<Type, IFreeSql> _dicCurd = new Dictionary<Type, IFreeSql>();
static Dictionary<string, IFreeSql> _dicCurd = new Dictionary<string, IFreeSql>();
static object _dicCurdLock = new object();
static IFreeSql GetCrud(IDbConnection dbconn)
{
if (dbconn == null) throw new ArgumentNullException($"{nameof(dbconn)} 不能为 null");
if (dbconn.ConnectionString == null) throw new ArgumentNullException($"{nameof(dbconn)}.ConnectionString 不能为 null");
Type dbconType = dbconn.GetType();
var connType = dbconType.UnderlyingSystemType;
if (_dicCurd.TryGetValue(connType, out var fsql)) return fsql;
if (_dicCurd.TryGetValue(dbconn.ConnectionString, out var fsql)) return fsql;
Type providerType = null;
switch (connType.Name)
@ -63,9 +64,9 @@ namespace FreeSql
}
lock (_dicCurdLock)
{
if (_dicCurd.TryGetValue(connType, out fsql)) return fsql;
if (_dicCurd.TryGetValue(dbconn.ConnectionString, out fsql)) return fsql;
lock (_dicCurdLock)
_dicCurd.Add(connType, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql);
_dicCurd.Add(dbconn.ConnectionString, fsql = Activator.CreateInstance(providerType, new object[] { null, null, null }) as IFreeSql);
}
return fsql;
}