10000 Add the ability to register Refit clients as keyed services by fubar-coder · Pull Request #1981 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add the ability to register Refit clients as keyed services #1981

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

Merged

Conversation

fubar-coder
Copy link
Contributor
@fubar-coder fubar-coder commented Apr 28, 2025

This PR fixes #1876.

  1. Added new constructor to AuthenticatedHttpClientHandler which doesn't automatically set the InnerHandler property
  2. Adds extension methods to register the Refit client as keyed service
  3. Added unit tests

Why did I add the new constructor to AuthenticatedHttpClientHandler?

  • To keep the PR as small as possible by avoiding the duplication of code
  • Enable the a behavior compatible with IHttpClientBuilder by ...
    • ... avoiding the usage of obsolete functions
    • ... avoid setting InnerHandler, because this will be done by the builder itself

Future changes (not scope of this PR)

  • AuthenticatedHttpClientHandler: Remove the old constructor
  • AuthenticatedHttpClientHandler: Remove the innerHandler parameter for the new constructor
  • AuthenticatedHttpClientHandler: Fix the call sites
  • Don't call the obsoleted ConfigureHttpMessageHandlerBuilder
  • Fix the unit tests

Behavioral changes

When no httpClientName was specified, the UniqueName.ForType<T> is used and the string representation of the serviceKey (when not null or empty string) gets appended to the unique type name, e.g. Refit.Implementation.Generated+IFooWithOtherAttribute, Refit.Tests, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null, ServiceKey=keyed

@fubar-coder fubar-coder marked this pull request as ready for review April 28, 2025 16:29
Copy link
codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 37.69231% with 81 lines in your changes missing coverage. Please review.

Project coverage is 83.03%. Comparing base (6ebeda5) to head (7536423).
Report is 188 commits behind head on main.

Files with missing lines Patch % Lines
...t.HttpClientFactory/HttpClientFactoryExtensions.cs 35.29% 72 Missing and 5 partials ⚠️
Refit/AuthenticatedHttpClientHandler.cs 62.50% 1 Missing and 2 partials ⚠️
Refit/UniqueName.cs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1981      +/-   ##
==========================================
- Coverage   87.73%   83.03%   -4.71%     
==========================================
  Files          33       37       +4     
  Lines        2348     2640     +292     
  Branches      294      380      +86     
==========================================
+ Hits         2060     2192     +132     
- Misses        208      362     +154     
- Partials       80       86       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisPulman
Copy link
Member

Hi Mark, thank you for this, please could you make your next contribution to provide suitable tests to ensure this change doesn't become affected by future additions and alterations within the code base.
I look forward to seeing your list of future changes completed.

@ChrisPulman ChrisPulman merged commit 8257b37 into reactiveui:main May 1, 2025
1 of 3 checks passed
@fubar-coder
Copy link
Contributor Author

@ChrisPulman Hi, I added some tests, but it was obviously not exhaustive enough, as I wasn't sure how I can test that the created Refit clients use the correct HttpMessageHandler instance. Any idea? I'd gladly create a follow-up PR.

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add support for keyed services
2 participants
0