Named client #1636
Replies: 2 comments 1 reply
-
|
Is this covered by Line 1185 in e5bc249 |
Beta Was this translation helpful? Give feedback.
-
|
The standalone IRefitHttpClientFactory from PR #1418 was not kept, but the exact scenario you describe (two instances of the same interface, different base URLs, retrieved by name) is now supported directly through keyed DI: AddKeyedRefitClient(serviceKey, ...). builder.Services.AddKeyedRefitClient<ISomeApi>("one")
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://url_one"));
builder.Services.AddKeyedRefitClient<ISomeApi>("two")
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://url_two"));Resolve by key: public class Middleware(
[FromKeyedServices("one")] ISomeApi apiOne,
[FromKeyedServices("two")] ISomeApi apiTwo) { ... }
// or
var apiOne = serviceProvider.GetRequiredKeyedService<ISomeApi>("one");This is the Refit equivalent of resolving a named HttpClient by key, and it works when the interface/schema is shared across multiple downstream services. It requires the keyed-services support in .NET 8+ DI. Available in Refit.HttpClientFactory (see AddKeyedRefitClient overloads). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I just found the PR #1418 which has already added named client. However I don't find the IRefitHttpClientFactory in the main branch.
Is there any plan to add this feature back? The named client can be very useful in some case.
Beta Was this translation helpful? Give feedback.
All reactions