question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does Grace support IAsyncDisposable?

See original GitHub issue

Does Grace automatically dispose not only services implementing IDisposable but also the newly introduced (.NET Standard 2.1 / .NET Core 3.0) async version named IAsyncDisposable?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Lex45xcommented, Oct 31, 2021

Cool, I’ve already started working on it.
Basically, we will have to make changes in the Grace and then in the Grace.DependencyInjection.Extensions package. I will open PR to Grace throughout next week, so we can discuss.

A few points I want to highlight:

  1. IAsyncDisposable supported from netstandard2.1, so I will add a new target framework and implement changes only for netstandard2.1.
  2. According to Microsoft documentation on using IAsyncDisposable and IDisposable simultaneously, IDisposable implementation will not be responsible for IAsyncDisposable resources cleanup. Related discussion is here.
2reactions
Lex45xcommented, Oct 28, 2021

the question would be what’s the use case as asp.net core won’t perform an async dispose of the container when shutting down so you’d need to call it yourself.

I will check that in detail, but as I can already see, AspNetCore 5.0+ supports IAsyncDisposable service providers: image

https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.serviceprovider?view=dotnet-plat-ext-5.0 https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httpresponse.registerfordisposeasync?view=aspnetcore-5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraceRegistration.cs
Grace Extensions for ASP.Net Core. Contribute to ipjohnson/Grace.DependencyInjection.Extensions development by creating an account on GitHub.
Read more >
Implementing both IDisposable and IAsyncDisposable
Proxy might not support IAsyncDisposable . Failing to cast object to IDisposable will present hard to catch bugs in your app.
Read more >
Implement a DisposeAsync method
If no synchronous disposable of your class is possible, having only IAsyncDisposable is acceptable. All of the guidance for implementing the ...
Read more >
How to properly dispose in AspNetCore application?
The quick answer implies that your AspNetCore aplication is stateless. ... Modern IoC frameworks, such as Grace supports lots of different ...
Read more >
How to properly use IAsyncDisposable in C#8
The interface requires an implementation of a method with the signature public ValueTask DisposeAsync(). That's it. However, there are multiple ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found