Skip to content
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

[Bug]: HttpClient named client with the same name overwrite ConfigureHttpClient BaseAddress #1686

Open
squadwuschel opened this issue Apr 23, 2024 · 0 comments
Labels

Comments

@squadwuschel
Copy link

Describe the bug 🐞

I am using named clients to Authorize my client access, and here I have multiple APIs using the same Named client.
Now I am creating multiple Refit Clients for multiple Interfaces (multiple different API URLs) and all use the same Named client to authenticate.

When I Inject the API Client Interfaces into my services/controller, from all Interfaces the BaseAdress is the last baseAddress from my Registered Refit Clients.

Step to reproduce

Here you can see my setup:

  services.AddHttpClient("GitHubClient", client =>
        {
            client.BaseAddress = new Uri("https://api.github.com/");
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            // Weitere Konfigurationen hier ...
        });
       
  services
       .AddRefitClient(typeof(IArticlesApi), null, $"GitHubClient")
       .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://myArticlesApi.com"));

  services
       .AddRefitClient(typeof(IContentApi), null, $"GitHubClient")
       .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://myContentApi.com"));

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

when I now inject the "IContentApi" and the "IArticlesApi" into an Controller or Service/Provider
the Client.BaseAdress on both injected Interfaces is "https://myContentApi.com" => the last registered c.BaseAddress.
That seems to be wrong I would say, because, when I Use multiple different named clients, then each BaseAddress is like expected.

Screenshots 🖼️

No response

IDE

Rider Windows

Operating system

Windows 10

Version

No response

Device

No response

Refit Version

7.0.0

Additional information ℹ️

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant