Proposal to fix Azure/azure-functions-host#7236 by removing the registration of HttpClient
from DI in the Functions Host.
Discussion link: #1913
Motivation.NET has an IHttpClientFactory
, which is the correct pattern for using HttpClient
with DI. The HttpClient
class was registered with DI early in Functions v2 and we didn't realize the mistake until we enabled Dependency Injection for .NET in-proc applications.
It's unclear as this would exist in customer constructor injection. I'm not sure whether it matters in this case, as we need to avoid this pattern, and the fix is pretty straightforward for customers.
Compat-mode supportWe could support a compat-mode flag here, if necessary. But because this is an incorrect pattern, I'd like to force customers to update their code.
AlternativesNone discussed.
DetectionIf we remove all usage of HttpClient
internally, we could maintain a DI factory so that, if called, it logs an exception that causes a host failure. Without an HttpClient
registered, customers will get a null ref in their constructors that have an HttpClient
parameter.
With a proper error message linking to breaking change documentation, we should be able to deflect support cases.
DocumentationThere is one place in our documentation that needs updating. However, this can be updated now with the proper pattern.
Components impactedJust the functions host.
PerformanceNo perf impact.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4