mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
IFreeSql 增加 IDisposable
This commit is contained in:
@ -11,7 +11,7 @@ using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FreeSql.Internal.CommonProvider {
|
||||
abstract partial class AdoProvider : IAdo {
|
||||
abstract partial class AdoProvider : IAdo, IDisposable {
|
||||
|
||||
protected abstract void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex);
|
||||
protected abstract DbCommand CreateCommand();
|
||||
|
@ -110,13 +110,6 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
public void CommitTransaction() => CommitTransaction(true);
|
||||
public void RollbackTransaction() => CommitTransaction(false);
|
||||
|
||||
public void Dispose() {
|
||||
Transaction2[] trans = null;
|
||||
lock (_trans_lock)
|
||||
trans = _trans.Values.ToArray();
|
||||
foreach (Transaction2 tran in trans) CommitTransaction(false, tran);
|
||||
}
|
||||
|
||||
public void Transaction(Action handler) {
|
||||
Transaction(handler, TimeSpan.FromSeconds(60));
|
||||
}
|
||||
@ -130,5 +123,35 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
~AdoProvider() {
|
||||
this.Dispose();
|
||||
}
|
||||
bool _isdisposed = false;
|
||||
public void Dispose() {
|
||||
if (_isdisposed) return;
|
||||
try {
|
||||
Transaction2[] trans = null;
|
||||
lock (_trans_lock)
|
||||
trans = _trans.Values.ToArray();
|
||||
foreach (Transaction2 tran in trans) CommitTransaction(false, tran);
|
||||
} catch { }
|
||||
|
||||
ObjectPool<DbConnection>[] pools = null;
|
||||
for (var a = 0; a < 10; a++) {
|
||||
try {
|
||||
pools = SlavePools.ToArray();
|
||||
SlavePools.Clear();
|
||||
break;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
if (pools != null) {
|
||||
foreach (var pool in pools) {
|
||||
try { pool.Dispose(); } catch { }
|
||||
}
|
||||
}
|
||||
try { MasterPool.Dispose(); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.CommonProvider {
|
||||
class CacheProvider : ICache {
|
||||
class CacheProvider : ICache, IDisposable {
|
||||
|
||||
public IDistributedCache Cache { get; private set; }
|
||||
private bool CacheSupportMultiRemove = false;
|
||||
@ -30,6 +30,16 @@ namespace FreeSql.Internal.CommonProvider {
|
||||
}
|
||||
}
|
||||
|
||||
~CacheProvider() {
|
||||
this.Dispose();
|
||||
}
|
||||
bool _isdisposed = false;
|
||||
public void Dispose() {
|
||||
if (_isdisposed) return;
|
||||
|
||||
Cache = null;
|
||||
}
|
||||
|
||||
public Func<object, string> Serialize { get; set; }
|
||||
public Func<string, Type, object> Deserialize { get; set; }
|
||||
|
||||
|
Reference in New Issue
Block a user