Skip to content

[API Proposal]: Consider adding methods to the HTTP Client factory that receive Type parameters instead of generic type parameters #104525

Open
@paulomorgado

Description

@paulomorgado

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions