Skip to content

Commit

Permalink
Make apps dispose just once (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankBakkerNl committed Jan 6, 2022
1 parent 04eae75 commit 786e7d0
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace NetDaemon.Common
public abstract class ApplicationContext : IAsyncDisposable, IApplicationMetadata, IApplicationContext
{
private readonly IServiceScope? _serviceScope;
private bool _disposed;

private Action? _configProvider;

Expand Down Expand Up @@ -152,12 +153,16 @@ public async Task InitializeAsync()
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
if (_disposed) return;

_disposed = true;

if (ApplicationInstance is IAsyncDisposable asyncDisposable)
{
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}

if (ApplicationInstance is IDisposable disposable)
else if (ApplicationInstance is IDisposable disposable)
{
disposable.Dispose();
}
Expand Down

0 comments on commit 786e7d0

Please sign in to comment.