-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when using Autofac Plugin with injection to a static methods #2307
Comments
Code below can solve some cases (injecting FeatureContext for example, but it not cover all scenarios. I think maybe we need a new attribute, FeatureDependencies (with logic like in ScenarioDependencies) or something like that. public class AutofacTestObjectResolver : ITestObjectResolver
{
public object ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
{
if (scenarioContainer.IsRegistered<IComponentContext>())
{
var componentContext = scenarioContainer.Resolve<IComponentContext>();
return componentContext.Resolve(bindingType);
}
return scenarioContainer.Resolve(bindingType);
}
} Thanks. |
Ah, yes, that is a problem. If you could provide a PR with a fix for it, that would be awesome and probably the quickest way to get it fixed. If you need help, you can join the #contributing channel on our discord server (https://go.specflow.org/join-contributing-on-discord). |
Fixed with #2315 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Crash when using dependency injection in static methods (i.e. hooks marked AfterFeature attribute)
SpecFlow Version:
Used Test Runner
Version number:
Project Format of the SpecFlow project
packages.config
<PackageReference>
tags.feature.cs files are generated using
SpecFlow.Tools.MsBuild.Generation
NuGet packageSpecFlowSingleFileGenerator
custom toolVisual Studio Version
Enable SpecFlowSingleFileGenerator Custom Tool
option in Visual Studio extension settingsAre the latest Visual Studio updates installed?
<Major>.<Minor>.<Patch>
.NET Framework:
Test Execution Method:
<SpecFlow> Section in app.config or content of specflow.json
Issue Description
Crash when using dependency injection in static methods (i.e. hooks marked AfterFeature attribute).
Autofac container created for Scenario and when time comes to resolve injection in static method it is already disposed.
Steps to Reproduce
You can reproduce it with creating hook with code below:
The text was updated successfully, but these errors were encountered: