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 · 1 comment
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

@TimothyMakkison
Copy link
Contributor

TimothyMakkison commented Oct 13, 2024

Hey, is this still an issue? I'm unable to replicate it in #1877. It looks like you register IGitHubClient and then fail to create type IGitHubApi, which is presumably not registered, causing the error.

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

2 participants