ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Does Grace support IAsyncDisposable? #243

Open silkfire opened 4 years ago

silkfire commented 4 years ago

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?

ipjohnson commented 4 years ago

Currently Grace only disposes IDisposable dependencies. Ultimately the problem lies in the fact that linq expressions don't support async so it's very hard to implement any of the async functionality.

silkfire commented 4 years ago

@silkfire Thanks for the update. I checked out the relevant issue over at csharplang and progress seems very slow. Let's hope this gets implemented soon enough!

Lex45x commented 3 years ago

@ipjohnson is this issue still relevant? Would be happy to look into it and contribute 😃

ipjohnson commented 3 years ago

Sorry I've been super busy and missed this notification. I think this issue is somewhat relevant, 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.

Lex45x commented 3 years ago

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

ipjohnson commented 3 years ago

I wasn't aware that was added. Looks like a good feature to add.

Lex45x commented 3 years ago

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.
ipjohnson commented 3 years ago

Sounds good, look forward to the PRs.