title: Resolve HttpClient depends on URL (with/without Proxy)
body: <p>The task is to configure proxy of HttpClient depends on an URL. For example, if an URL contains &quot;hostname.com&quot;, must be set.</p>
  <p>What is the best practice?</p>
  <p>Is the following a solution?</p>
  <p>egister different HttpClients in DI as:</p>
  <pre><code>-- Configured typed HttpClients with different proxies for each service
  services.AddHttpClient&lt;Service1&gt;().ConfigurePrimaryHttpMessageHandler(GetHttpHandlerSetter(s =&gt; s.Service1));
  services.AddHttpClient&lt;Service2&gt;().ConfigurePrimaryHttpMessageHandler(GetHttpHandlerSetter(s =&gt; s.Service2));
  
  -- Configured named HttpClient without proxy
  services.AddHttpClient(&quot;NoProxy&quot;);
  </code></pre>
  <p>And Service1 and Service2 will resolve IHttpClientFactory:</p>
  <pre><code>    public class Service1
  {
      readonly IHttpClientFactory _httpClientFactory;
  
      public IdgwConnectorManager(IHttpClientFactory httpClientFactory)
      {
          _httpClientFactory = httpClientFactory;
      }
      
      public void Get(string url)
      {
          if (url...)
          {
              _httpClientFactory.CreateClient(nameof(Service1));
          }
          else
          {
              _httpClientFactory.CreateClient(&quot;NoProxy&quot;);
          }
      }
  }
  </code></pre>