-
Notifications
You must be signed in to change notification settings - Fork 11
Scoped container dispose issue #100
Comments
Basically you need link Register relay disposers directly into container from arguments with Example: internal class SpecFlowRuntimePlugin : IRuntimePlugin
{
public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters, UnitTestProviderConfiguration unitTestProviderConfiguration)
{
runtimePluginEvents.CustomizeFeatureDependencies += RuntimePluginEventsOnCustomizeFeatureDependencies;
runtimePluginEvents.CustomizeScenarioDependencies += RuntimePluginEventsOnCustomizeScenarioDependencies;
}
private void RuntimePluginEventsOnCustomizeFeatureDependencies(object sender, CustomizeFeatureDependenciesEventArgs e)
{
// Initialize child DI scope for feature
var disposer = new RelayDispose(() =>
{
// Dispose child DI scope here
});
e.ObjectContainer.RegisterInstanceAs(disposer, dispose: true);
}
private void RuntimePluginEventsOnCustomizeScenarioDependencies(object sender, CustomizeScenarioDependenciesEventArgs e)
{
// Initialize child DI scope for scenario
var disposer = new RelayDispose(() =>
{
// Dispose child DI scope here
});
e.ObjectContainer.RegisterInstanceAs(disposer, dispose: true);
}
} public class RelayDispose : IDisposable
{
private readonly Action _disposeAction;
public RelayDispose(Action disposeAction)
{
_disposeAction = disposeAction;
}
public void Dispose()
{
_disposeAction?.Invoke();
}
} I will create PR if you are still supporting this package. Please, let me know. |
Hey @BlackGad, thanks for reporting this issue. These changes were introduced in #74 and in hindsight I should've had a better understanding of it before merging. For the next major release (aiming for right after they release SpecFlow v4) I'll be reworking a lot of these changes, and I'm also going to bring it more in line with how the official Autofac plugin works (e.g. they introduced a a Having said that I will consider your solution because it makes a lot of sense, so I'm adding it to the milestone. No need for a PR because the code will probably change a lot before release. Thanks again! |
Thank you! But it is crucial issue for me right now :) Is there any chance to provide patch to current released version? And happy new year! |
Btw do you know specflow 4 release date? |
Unfortunately I won't be patching the current version, all my available time will be focused on the v4 release (first version is in preview right now). If you want to complete negate the disposing of classes I'd recommend trying Sorry for the inconvenience. |
Is this a bug or a feature? I'm trying to move from AdCodicem.SpecFlow.MicrosoftDependencyInjection, but I get mulitple scope/dispose issues which are hard to find out. (locally it works, on CI it fails) |
@304NotModified Hmm, weird that it works locally but fails in CI -- sounds like a bug. Would you be willing to check against I am looking to fix most of the async and disposable problems with the release of SpecFlow v4 (they did a lot of work in there which I depend on), but unfortunately the release of v4 (or even the current state of SpecFlow) seems very unclear atm. |
Closing this issue because the plugin will be donated to Reqnroll. |
Hi!
Faced with an issue when scenario and feature containers were disposed too early in execution context.
You are handling
RuntimePluginTestExecutionLifecycleEvents.AfterScenario
andRuntimePluginTestExecutionLifecycleEvents.AfterFeature
events to dispose scoped container. There are additional functionality after that events still in scope of scenario and feature.Is it possible to postpone scoped DI dispose operations?
The text was updated successfully, but these errors were encountered: