Refactor HttpClientFactoryExtensions to simplify code structure #2042
+724
−297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
IHttpClientBuilderto simplify Refit client configurationWhat is the current behavior?
Currently, when configuring Refit clients, developers must manually specify the HTTP client configuration name as a string, which is error-prone and difficult to maintain. For example:
Additionally, existing extension method implementations have significant code duplication, making maintenance difficult.
What is the new behavior?
IHttpClientBuilderextension methods that automatically retrieve the HttpClient name frombuilder.NameWhat might this PR break?
This change is API-compatible but binary-incompatible:
API compatible: All existing code continues to work without modification
Binary incompatible: Applications referencing this library need recompilation due to some required parameters becoming optional
Parameter changes:
Impact on existing code:
Other information:
Technical implementation:
Added 4 core private methods:
AddRefitClientCore(non-generic, non-keyed)AddKeyedRefitClientCore(non-generic, keyed)AddRefitClientCore<T>(generic, non-keyed)AddKeyedRefitClientCore<T>(generic, keyed)T4 template generates 16 variants covering:
Improved error handling: