Open
Description
Updated by @CarnaViire
API:
namespace Microsoft.Extensions.DependencyInjection;
public static class HttpClientBuilderExtensions
{
public static IHttpClientBuilder AddTypedClient(
this IHttpClientBuilder builder,
Type clientType,
Type? ImplementationType = null);
}
Usage:
services.AddHttpClient(name)
.AddTypedClient(clientType, clientImplementationType);
Original issue by @paulomorgado
Background and motivation
Sometimes I have the need to register HTTP clients from configuration files and, for that, I need to construct a generic method for each type.
API Proposal
namespace Microsoft.Extensions.DependencyInjection;
public static class HttpClientFactoryServiceCollectionExtensions
{
public static IHttpClientBuilder AddHttpClient(
this IServiceCollection services,
Type clientType,
Type ImplementationType);
}
API Usage
service.AddHttpClient(clientType, implementationType);
Alternative Designs
No response
Risks
There might be a risk for overloads with factory methods, as correctness might be hard to guarantee.