Refit: retarget net10.0, Refit 15.2.0, AddRefitGeneratedClient, error-handling and headers samples - #2136
Merged
vladimir-pecanac-main merged 3 commits intoAug 24, 2026
Conversation
…-handling and headers samples - RefitLibrary and Tests retargeted net6.0 -> net10.0 - Refit and Refit.HttpClientFactory 6.3.2 -> 15.2.0 - Microsoft.Extensions.Hosting 6.0.1 -> 10.0.0 - Microsoft.AspNetCore.Mvc.Testing 6.0.5 -> 10.0.0 - Microsoft.NET.Test.Sdk 16.11.0 -> 17.11.1 - Program.cs registers with AddRefitGeneratedClient<IUsersClient>(); on Refit 15.x AddRefitClient<T>() throws NotSupportedException without the opt-in Refit.Reflection package - IUsersClient gains an ApiResponse<User> endpoint, a query-string plus CancellationToken overload, and an interface-level [Headers] attribute; Program.cs shows the ApiResponse call site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updates the
dotnet-client-libraries/Refitsample for the refresh of Using Refit to Consume APIs in C#.Retarget and pins
RefitLibraryandTestsretargetednet6.0->net10.0RefitandRefit.HttpClientFactory6.3.2 -> 15.2.0Microsoft.Extensions.Hosting6.0.1 -> 10.0.0Microsoft.AspNetCore.Mvc.Testing6.0.5 -> 10.0.0Microsoft.NET.Test.Sdk16.11.0 -> 17.11.1xunit,xunit.runner.visualstudioandcoverlet.collectorleft untouched: the test project builds and passes onnet10.0with the versions it already hadRegistration path
On Refit 15.x
services.AddRefitClient<IUsersClient>()compiles and then throwsSystem.NotSupportedExceptionat DI resolution, because the reflection request builder moved into the opt-inRefit.Reflectionpackage in v14.Program.csnow registers withAddRefitGeneratedClient<IUsersClient>(), which resolves the source-generated implementation and needs no extra package.RestService.For<T>is unaffected, which is why the integration tests passed while the console entry point did not.New sample code
IUsersClientgainsTask<ApiResponse<User>> GetUserResponse(int id)for the return-type-instead-of-catching styleGetAll([Query] string? name, CancellationToken token)overload and an interface-level[Headers]attributeProgram.csshows theApiResponsecall siteVerified on SDK 10.0.302 / runtime 10.0.10:
dotnet build -c Release0 errors 0 warnings;dotnet test -c Release4/4 passed;dotnet runcompletes the full CRUD sequence against the live jsonplaceholder API and printsFailed: NotFoundfor the 404 response case.