Do not warn about IDisposables in IHostedService
See original GitHub issueWhile during my unit tests, I was suprised that the IDisposable that I declare in my [SetUp] method and disposed in my [TearDown] were correctly understood by IDisposableAnalyzers.
I’ve seen that there might be an exception somewhere, because I saw those unit tests : https://github.com/DotNetAnalyzers/IDisposableAnalyzers/blob/759fc9bb091625c711675513729de83789e544d5/IDisposableAnalyzers.Test/IDISP002DisposeMemberTests/ValidCode.TestFixture.cs
Would it be possible to do the same for IHostedService
? I think it’s a common pattern for background tasks in ASP.net core.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.ihostedservice?view=dotnet-plat-ext-3.0
There are two methods : StartAsync
and StopAsync
which are called by the IHost
implementation.
If I declare my Disposable in the StartAsync, and dispose them properly in the StopAsync, I think that it’s a good usage of the IDisposable pattern.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top GitHub Comments
Here is an example: (written here, so it might not build)
Still triggers IDISP006 with this code: