You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Singleton services are not disposed when using Reqnroll.Microsoft.Extensions.DependencyInjection.ScenarioDependenciesAttribute to add servicess to the Microsoft.Extensions.DependencyInjection.ServiceCollection.
Steps to Reproduce
Register a disposable singleton service in the service collection, using ScenarioDependenciesAttribute, ie [ScenarioDependencies] public static IServiceCollection RegisterMyServices().
Have the service injected into some class used by a step (resolved from the service provider)
When the test run ends, notice that the Dispose method of the disposable singleton service is not triggered.
Please see MySingletonService for the service that should be disposed (but never is).
Here's the output of the debug window when running it (abbreviated for brevity and privacy reasons):
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.13\System.Threading.Tasks.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
16:59:29:929 MySingletonService.MySingletonService executing <<<<<<<<<<<<<<<<<<<<<<
16:59:29:929 MySingletonService.UseTheService executing <<<<<<<<<<<<<<<<<<<<<<
16:59:30:001 The thread '.NET Long Running Task' (8584) has exited with code 0 (0x0).
16:59:30:001 The program '[36444] testhost.exe' has exited with code 0 (0x0).
As you can see MySingletonService.Dispose executing <<<<<<<<<<<<<<<<<<<<<< is never outputted, nor is the debugger triggering any breakpoints for the Dispose method.
gasparnagy
changed the title
Root service provider not disposed
Reqnroll.Microsoft.Extensions.DependencyInjection: Root service provider not disposed
Feb 19, 2025
@304NotModified The dispose behavior of MSDI is pretty strange but this is now addressed with the new design model. However, we can still do a quick fix here. And yes, it will dispose things like FeatureContext (that is normally bad), but fortunately at the current moment the dispose method of FeatureContext and ScenarioContext does not do anything, so it is not causing a direct issue.
Reqnroll Version
2.3.0
Which test runner are you using?
MSTest
Test Runner Version Number
3.4.3
.NET Implementation
.NET 8.0
Test Execution Method
Visual Studio Test Explorer
Content of reqnroll.json configuration file
Not sure where to find it, but this is what I found when I searched for the file name on the Windows system drive.
Issue Description
Singleton services are not disposed when using
Reqnroll.Microsoft.Extensions.DependencyInjection.ScenarioDependenciesAttribute
to add servicess to theMicrosoft.Extensions.DependencyInjection.ServiceCollection
.Steps to Reproduce
ScenarioDependenciesAttribute
, ie[ScenarioDependencies] public static IServiceCollection RegisterMyServices()
.Dispose
method of the disposable singleton service is not triggered.Link to Repro Project
https://github.com/olaviedoc/ReqnrollDisposeBugRepro
The text was updated successfully, but these errors were encountered: