Skip to content

Commit

Permalink
Simplified and improved async disposal in the ASP.NET Core integratio…
Browse files Browse the repository at this point in the history
…n package. Now any component implementing IAsyncDisposable will be disposed, not only those that also implement IDisposable. #791.
  • Loading branch information
dotnetjunkie committed Apr 30, 2020
1 parent 737da20 commit 4763808
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace SimpleInjector.Integration.AspNetCore
{
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using SimpleInjector;
Expand Down Expand Up @@ -37,24 +36,9 @@ private void ConfigureRequestScoping(IApplicationBuilder builder)
{
await next();
await DisposeAsync(scope);
await scope.DisposeAsync();
}
});
}

private static async ValueTask DisposeAsync(Scope scope)
{
IDisposable[] disposables = scope.GetDisposables();

// Dispose in reverse order
for (int index = disposables.Length - 1; index >= 0; index--)
{
if (disposables[index] is IAsyncDisposable asyncDisposable)
{
// We don't need to catch-and-continue; Scope will guarantee everything is disposed.
await asyncDisposable.DisposeAsync();
}
}
}
}
}

0 comments on commit 4763808

Please sign in to comment.