HttpClientFactoryServiceCollectionExtensions.AddHttpClient has several overloads. Some of them has AddHttpClient<TClient> signature and other has AddHttpClient<TClient,TImplementation>.
According to the Microsoft documentation:
AddHttpClient<TClient,TImplementation> - Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.
AddHttpClient<TClient> - Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.
I dont' understand when I supposed to use the first overload and when I supposed to use the second overload.
The difference is that the second one will register
TImplementationasTClient, i.e. if you have an interface likeIMyTypedClientyou want to resolve then you will use the first one:And then you will resolve
IMyTypedClientin some service.And if you want to resolve the implementation directly then you will use the first one -
builder.Services.AddHttpClient<MyTypedClientImpl>();and then you will need to resolveMyTypedClientImpl.Basically the relation is the same as between
Add{Lifetime}<TService>andAdd{Lifetime}<TService,TImplementation>methods.