Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
IAsyncDisposable support (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
klemmchr authored Jun 8, 2022
1 parent 035410d commit cd143b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static string GenerateComponentCode(MvvmComponentClassContext componentC
namespace {componentNamespace}
{{
partial class {componentClassName} : IDisposable
partial class {componentClassName} : IDisposable, IAsyncDisposable
{{
private AsyncServiceScope? _scope;
Expand Down Expand Up @@ -235,12 +235,35 @@ public void Dispose()
_scope = null;
Dispose(true);
GC.SuppressFinalize(this);
IsDisposed = true;
}}
}}
protected virtual void Dispose(bool disposing)
{{
}}
public async ValueTask DisposeAsync()
{{
if (!IsDisposed)
{{
if (_scope is not null)
{{
await _scope.Value.DisposeAsync();
_scope = null;
}}
await DisposeAsyncCore();
Dispose(false);
GC.SuppressFinalize(this);
IsDisposed = true;
}}
}}
protected virtual ValueTask DisposeAsyncCore()
{{
return ValueTask.CompletedTask;
}}
}}
}}
";
Expand Down
5 changes: 0 additions & 5 deletions src/MvvmBlazor.Tests/Components/MvvmComponentBaseTTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,5 @@ public Task AfterRenderAsync(bool firstRender)
{
return OnAfterRenderAsync(firstRender);
}

public Task ParametersAsync(ParameterView parameters)
{
return SetParametersAsync(parameters);
}
}
}

0 comments on commit cd143b5

Please sign in to comment.