Skip to content

Commit

Permalink
fix disposing of direct instantiated objects in calalog service dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
nsedoud authored Aug 31, 2020
1 parent 8f84bd3 commit 313879e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services
{
public class IntegrationEventLogService : IIntegrationEventLogService
public class IntegrationEventLogService : IIntegrationEventLogService,IDisposable
{
private readonly IntegrationEventLogContext _integrationEventLogContext;
private readonly DbConnection _dbConnection;
private readonly List<Type> _eventTypes;
private volatile bool disposedValue;

public IntegrationEventLogService(DbConnection dbConnection)
{
Expand Down Expand Up @@ -89,5 +90,25 @@ private Task UpdateEventStatus(Guid eventId, EventStateEnum status)

return _integrationEventLogContext.SaveChangesAsync();
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_integrationEventLogContext?.Dispose();
}


disposedValue = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

namespace Catalog.API.IntegrationEvents
{
public class CatalogIntegrationEventService : ICatalogIntegrationEventService
public class CatalogIntegrationEventService : ICatalogIntegrationEventService,IDisposable
{
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
private readonly IEventBus _eventBus;
private readonly CatalogContext _catalogContext;
private readonly IIntegrationEventLogService _eventLogService;
private readonly ILogger<CatalogIntegrationEventService> _logger;
private volatile bool disposedValue;

public CatalogIntegrationEventService(
ILogger<CatalogIntegrationEventService> logger,
Expand Down Expand Up @@ -65,5 +66,24 @@ await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () =>
await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction);
});
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
(_eventLogService as IDisposable)?.Dispose();
}

disposedValue = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

0 comments on commit 313879e

Please sign in to comment.