Skip to content

ability of to pass parameter for HttpMessageHandler constructorย #36061

Open
@candidodmv

Description

@candidodmv

Is your feature request related to a problem? Please describe.

I'm am trying to integrated Fusillade with IHttpClientFactory but it's handler needs a parameter during it's initialization, as sample code:

var moreThanSpeculativeButLessThanBAckground = new RateLimitedHttpMessageHandler(
                new HttpClientHandler(), 
                Priority.Explicit, 
                15);

So, to achive this using the current IHttpClient factory is registering one named HttpClient for each Priority, wich the minimum is the following:

public enum Priority
{
	/// <summary>
	/// A speculative priority where we aren't sure.
	/// </summary>
	Speculative = 10,
	/// <summary>
	/// This is a instance which is initiated by the user.
	/// </summary>
	UserInitiated = 100,
	/// <summary>
	/// This is background based task.
	/// </summary>
	Background = 20,
	/// <summary>
	/// This is a explicit task.
	/// </summary>
	Explicit = 0
}

Then, the issue is raised:

Supouse that my application is consuming only one API with their spcifics configurations, I need register at least the number of existing priorities, in that case is 4, but if have two services to consume the math is number of targeting endpoints * number of priorities, currently this cal is :

2 targeting API's X 4 possibile priorieties = 8

this situation become unaccetable, depending the number of target API's that the application is using.

Describe the solution you'd like

The most clear solution that I currently can see is create a new overload to CreateClient method in IHttpClientFactory that accept an action to configure the handlers at creating time, so we can pass any kind of parameter to any Handler that is need to configure, providing the correct constructor parameters.

Futhemore I'm miss a way to instantiate a new HttpClient registered using the type as a generic parameter, what in this currently context make more sense than ever, something like this:

IHttpClientFactory.CreateClient<TTypedClient>(Action<HttpMessageHandlerBuilder> configureBuilder)

or even better:

IHttpClientFactory.CreateClient<TTypedClient, THttpMessageHandler>(Action<IList<THttpMessageHandler>> configureHandlers)

Describe alternatives you've considered

I don't find any workaround to solve this limitation.

Additional context

All of this context described above is related for a Xamarin application.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions