-
Notifications
You must be signed in to change notification settings - Fork 54
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
Injecting ScenarioContext when overriding HttpClientHandler SendAsync breaks execution. #333
Comments
@13dante04 Thank you for the repro project. It helped a lot to analyze the issue. Pretty complex. In order to understand the problem, please let me summarize first how the Reqnroll MSDI plugin works (this is not the full behavior, but the core concept):
Your problem seems to be rooted in how the Basically the suggestion there is not to use a message handler that has a reference to any context-specific state, but pass any state required through the For me the fundamental question is whether the sub-scoping our plugin does is really a good idea or we should rather build a service provider for each scenario execution based on the service collection. (Although with this registering shared, singleton objects would not be possible easily.) Your input is appreciated on this, because it seems we need to re-design the MSDI plugin anyway. For you (I guess) the question is if we can have a workaround. I played with it and found two worarounds: Workaround 1: Pass ScenarioContext to the message handler, via the properties of the request.In your example, there is a The message handler can then get the Workaround 2: Create a new scenario-specific service provider to resolve http clientsSince you cannot use the
|
Reqnroll Version
2.2.1
Which test runner are you using?
xUnit
Test Runner Version Number
2.8.2
.NET Implementation
.NET 8.0
Test Execution Method
ReSharper Test Runner
Content of reqnroll.json configuration file
No response
Issue Description
When trying to inject ScenarioContext in an HttpClient handler, when using Microsoft DI. This error occurs
Use case is, setting data in the scenario context, which is later on set as a request header.
In this specific scenario, I'm trying to get the scenario context when overriding the SendAsync method.
This happens during test execution, when sending an http request, not before test execution as the message says
There is a repro project but here's also the block where scenario context is being accessed.
Entire stack trace attached as a file.
trace.txt
Steps to Reproduce
Use Reqnroll.Microsoft.Extensions.DependencyInjection;
Add an HttpClient with a custom HttpMessageHandler
Inject ScenarioContext in the HttpMessageHandler
Get error message
Link to Repro Project
https://github.com/13dante04/Reqnroll.MSDI
The text was updated successfully, but these errors were encountered: