In my app I will have few TypedClient services. However, these classes will share a bunch of methods. My solution to this is to create CustomHttpClient:
public class CustomHttpClient:HttpClient
{
//here shared methods
}
Then my typed client classes will use this derived class instead of standard HttpClient:
public class MyService : IMyService
{
public SomeService(CustomHttpClient client, IConfiguration configuration){}
}
However, if i try to register this service in startup i get an error that there is no suitable constructor for 'MyService' :
services.AddHttpClient<IMyService, MyService>();
In the documentation I have found:
Does it mean, that it cannot accept a subclass of HttpClient? If this is the case, then my only solution would be to implement shared methods as HttpClient extension methods ( i don't really like this solution). Is there maybe a workaround this, or extension methods are my only way out? I have tried registering also CustomHttpClient so DI container would find it but the error is still the same. What can you advise me?