ObjectContainer.IsRegistered<T>()
does not walk up the inheritance chain, even though Resolve<T>()
does, giving misleading results
#2759
Labels
SpecFlow Version
3.9.74
Which test runner are you using?
xUnit
Test Runner Version Number
2.4.1
.NET Implementation
.NET 8.0
Project Format of the SpecFlow project
Sdk-style project format
.feature.cs files are generated using
SpecFlow.Tools.MsBuild.Generation NuGet package
Test Execution Method
Visual Studio Test Explorer
SpecFlow Section in app.config or content of specflow.json
{
"$schema": "https://specflow.org/specflow-config.json",
"stepAssemblies": [
{
"assembly": "<my_common_assembly>"
}
]
}
Issue Description
I am registering services in the Global container in a [BeforeTestRun] method due to Issue #2580.
In another portion of my project, I am attempting to proactively check whether this dependency has been registered so I can give a helpful error message:
This call to
IsRegistered()
is returning false, even though the object is registered, just not at the hierarchy level of the current ObjectContainer... If I comment out myif
check, the object resolves as expected becauseResolve()
actually walks up the inheritance chain to find an object. But it seems as ifIsRegistered()
simply stops and returns false if it isn't in the immediate scope of the current ObjectContainer - which is not what I'd expect as a user.NOTE: I've devised a workaround by introducing an extension method as follows, which works:
Steps to Reproduce
TestThread
orFeature
level.container.IsRegistered<MyObj>()
at the scenario level => FAILcontainer.Resolve<MyObj>()
at the scenario level => SUCCESSMy issue description also provides a decent description of the repro.
Link to Repro Project
Closed source project
The text was updated successfully, but these errors were encountered: