Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 313879e

Browse files
authored
fix disposing of direct instantiated objects in calalog service #1392 (#1395)
1 parent 8f84bd3 commit 313879e

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/BuildingBlocks/EventBus/IntegrationEventLogEF/Services/IntegrationEventLogService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services
1717
{
18-
public class IntegrationEventLogService : IIntegrationEventLogService
18+
public class IntegrationEventLogService : IIntegrationEventLogService,IDisposable
1919
{
2020
private readonly IntegrationEventLogContext _integrationEventLogContext;
2121
private readonly DbConnection _dbConnection;
2222
private readonly List<Type> _eventTypes;
23+
private volatile bool disposedValue;
2324

2425
public IntegrationEventLogService(DbConnection dbConnection)
2526
{
@@ -89,5 +90,25 @@ private Task UpdateEventStatus(Guid eventId, EventStateEnum status)
8990

9091
return _integrationEventLogContext.SaveChangesAsync();
9192
}
93+
94+
protected virtual void Dispose(bool disposing)
95+
{
96+
if (!disposedValue)
97+
{
98+
if (disposing)
99+
{
100+
_integrationEventLogContext?.Dispose();
101+
}
102+
103+
104+
disposedValue = true;
105+
}
106+
}
107+
108+
public void Dispose()
109+
{
110+
Dispose(disposing: true);
111+
GC.SuppressFinalize(this);
112+
}
92113
}
93114
}

src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515
namespace Catalog.API.IntegrationEvents
1616
{
17-
public class CatalogIntegrationEventService : ICatalogIntegrationEventService
17+
public class CatalogIntegrationEventService : ICatalogIntegrationEventService,IDisposable
1818
{
1919
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
2020
private readonly IEventBus _eventBus;
2121
private readonly CatalogContext _catalogContext;
2222
private readonly IIntegrationEventLogService _eventLogService;
2323
private readonly ILogger<CatalogIntegrationEventService> _logger;
24+
private volatile bool disposedValue;
2425

2526
public CatalogIntegrationEventService(
2627
ILogger<CatalogIntegrationEventService> logger,
@@ -65,5 +66,24 @@ await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () =>
6566
await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction);
6667
});
6768
}
69+
70+
protected virtual void Dispose(bool disposing)
71+
{
72+
if (!disposedValue)
73+
{
74+
if (disposing)
75+
{
76+
(_eventLogService as IDisposable)?.Dispose();
77+
}
78+
79+
disposedValue = true;
80+
}
81+
}
82+
83+
public void Dispose()
84+
{
85+
Dispose(disposing: true);
86+
GC.SuppressFinalize(this);
87+
}
6888
}
6989
}

0 commit comments

Comments
 (0)