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]: Naming the interface to end with "Client" will result in an error during injection. #1597

Open
ivorfeng0504 opened this issue Nov 14, 2023 · 0 comments
Labels

Comments

@ivorfeng0504
Copy link

Describe the bug 🐞

Example: IGitHubApi ,This is a normal interface that the program can register.

public interface IGitHubApi
{
    [Get("/users/{user}")]
    Task<User> GetUser(string user);
}
---
services
    .AddRefitClient<IGitHubApi>()
    .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.github.com"));

However, if IGitHubApi is changed to IGitHubClient and nothing else is changed

public interface IGitHubClient
{
    [Get("/users/{user}")]
    Task<User> GetUser(string user);
}
---
services
    .AddRefitClient<IGitHubClient>()
    .ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.github.com"));

The following exception will be thrown during injection:

None of the constructors found on type 'Refit.Implementation.Generated+IGitHubApi' can be invoked with the available services and parameters:
Cannot resolve parameter 'Refit.IRequestBuilder requestBuilder' of constructor 'Void .ctor(System.Net.Http.HttpClient, Refit.IRequestBuilder)'.

Step to reproduce

  1. Create an interface with a name ending in "Client".
  2. Use the HttpClientFactory method to register the interface with the application.
  3. Inject the interface into the controller and call it

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

This should happen...

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows

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