Skip to content

Commit ef32b7f

Browse files
committed
wip: 更新 Disposable 相关类
1 parent 6a553ac commit ef32b7f

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

src/OSharp.EntityFrameworkCore/UnitOfWork.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,21 @@ protected override void Dispose(bool disposing)
264264

265265
base.Dispose(disposing);
266266
}
267-
267+
268+
/// <summary>
269+
/// 重写以实现释放派生类资源的逻辑
270+
/// </summary>
271+
protected override void Disposing()
272+
{
273+
foreach (var contexts in _contextDict.Values)
274+
{
275+
foreach (var context in contexts)
276+
{
277+
context.Dispose();
278+
}
279+
}
280+
}
281+
268282
/// <summary>
269283
/// 对数据库连接开启事务
270284
/// </summary>

src/OSharp.Utils/Data/Disposable.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------
1+
// -----------------------------------------------------------------------
22
// <copyright file="Disposable.cs" company="OSharp开源团队">
33
// Copyright (c) 2014-2020 OSharp. All rights reserved.
44
// </copyright>
@@ -21,12 +21,22 @@ public abstract class Disposable : IDisposable
2121

2222
protected virtual void Dispose(bool disposing)
2323
{
24+
if (Disposed)
25+
{
26+
return;
27+
}
2428
if (disposing)
2529
{
26-
Disposed = true;
30+
Disposing();
2731
}
32+
Disposed = true;
2833
}
2934

35+
/// <summary>
36+
/// 重写以实现释放派生类资源的逻辑
37+
/// </summary>
38+
protected abstract void Disposing();
39+
3040
/// <summary>执行与释放或重置非托管资源关联的应用程序定义的任务。</summary>
3141
public void Dispose()
3242
{
@@ -39,4 +49,4 @@ public void Dispose()
3949
Dispose(false);
4050
}
4151
}
42-
}
52+
}

src/OSharp.Utils/Logging/RollingFile/RollingFileLoggerProvider.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------
1+
// -----------------------------------------------------------------------
22
// <copyright file="RollingFileLoggerProvider.cs" company="OSharp开源团队">
33
// Copyright (c) 2014-2017 OSharp. All rights reserved.
44
// </copyright>
@@ -101,5 +101,13 @@ protected void RollFiles()
101101
}
102102
}
103103
}
104+
105+
/// <summary>
106+
/// 重写以实现释放派生类资源的逻辑
107+
/// </summary>
108+
protected override void Disposing()
109+
{
110+
111+
}
104112
}
105-
}
113+
}

src/OSharp.Utils/Reflection/ComLibraryLoader.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------
1+
// -----------------------------------------------------------------------
22
// <copyright file="ComLibraryLoader.cs" company="OSharp开源团队">
33
// Copyright (c) 2014-2017 OSharp. All rights reserved.
44
// </copyright>
@@ -101,13 +101,12 @@ public object CreateObjectFromPath(string dllPath, Guid clsid, bool setSearchPat
101101
return Activator.CreateInstance(type);
102102
}
103103

104-
protected override void Dispose(bool disposing)
104+
/// <summary>
105+
/// 重写以实现释放派生类资源的逻辑
106+
/// </summary>
107+
protected override void Disposing()
105108
{
106-
if (!Disposed)
107-
{
108-
NativeMethods.FreeLibrary(_lib);
109-
}
110-
base.Dispose(disposing);
109+
NativeMethods.FreeLibrary(_lib);
111110
}
112111
}
113-
}
112+
}

src/OSharp/Dependency/ServiceLocator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,12 @@ public async Task<TResult> ExecuteScopedWorkAsync<TResult>(Func<IServiceProvider
273273
}
274274
}
275275

276-
protected override void Dispose(bool disposing)
276+
/// <summary>
277+
/// 重写以实现释放派生类资源的逻辑
278+
/// </summary>
279+
protected override void Disposing()
277280
{
278281
_services = null;
279282
_provider = null;
280-
base.Dispose(disposing);
281283
}
282-
}
284+
}

src/OSharp/EventBuses/Internal/EventHandlerDisposeWrapper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ public EventHandlerDisposeWrapper(IEventHandler eventHandler, Action disposeActi
3030
/// </summary>
3131
public IEventHandler EventHandler { get; set; }
3232

33-
protected override void Dispose(bool disposing)
33+
/// <summary>
34+
/// 重写以实现释放派生类资源的逻辑
35+
/// </summary>
36+
protected override void Disposing()
3437
{
35-
if (!Disposed)
36-
{
37-
_disposeAction?.Invoke();
38-
}
39-
base.Dispose(disposing);
38+
_disposeAction?.Invoke();
4039
}
41-
}
40+
}

0 commit comments

Comments
 (0)