Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an Error in ConfigureHttpClient when custom IForwarderHttpClientFactory is added #1799

Closed
Kahbazi opened this issue Jul 9, 2022 · 1 comment · Fixed by #1805
Closed
Labels
Type: Idea This issue is a high-level idea for discussion.

Comments

@Kahbazi
Copy link
Collaborator

Kahbazi commented Jul 9, 2022

What should we add or change to make your life better?

Throw an exception in ConfigureHttpClient when custom IForwarderHttpClientFactory is added stating that "You couldn't call ConfigureHttpClient when another type is added for IForwarderHttpClientFactory. "

Why is this important to you?

I had ConfigureHttpClient in my code to configure SslOptions and lately I added a custom IForwarderHttpClientFactory. Now this wouldn't work because ConfigureHttpClient would add its own IForwarderHttpClientFactory and ignore the DiagnosticsHandlerFactory. I couldn't figure out why DiagnosticsHandlerFactory wasn't working until I checked the source code.

I suggest to throw an exception in ConfigureHttpClient if any other implementation of IForwarderHttpClientFactory beside ForwarderHttpClientFactory is added, in order to reduce the debugging time for others.

Btw this is my code:

services.AddSingleton<IForwarderHttpClientFactory, DiagnosticsHandlerFactory>();
services.AddReverseProxy()
    .ConfigureHttpClient((context, handler) =>
    {
        handler.SslOptions = ...
    }
@Kahbazi Kahbazi added the Type: Idea This issue is a high-level idea for discussion. label Jul 9, 2022
@adityamandaleeka
Copy link
Member

@Kahbazi This sort of thing is difficult to do with the way the service collection works. Detecting the presence of the prior service might be tricky.

You're welcome to try an experiment to see if this would be practical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Idea This issue is a high-level idea for discussion.
Projects
None yet
3 participants