Add method CreateHttpClientFactory (#1325)

* Add method CreateHttpClientFactory

* rev
This commit is contained in:
Stef Heyenrath
2025-07-08 10:50:30 +02:00
committed by GitHub
parent 35cd06b47b
commit 6c61f87ef3
3 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
// Copyright © WireMock.Net
#if NET5_0_OR_GREATER
using System;
using System.Net.Http;
using WireMock.Server;
namespace WireMock.Http;
internal class WireMockHttpClientFactory(WireMockServer server, params DelegatingHandler[] handlers) : IHttpClientFactory
{
private readonly Lazy<HttpClient> _lazyHttpClient = new(() => server.CreateClient());
public HttpClient CreateClient(string name)
{
return handlers.Length > 0 ? server.CreateClient(handlers) : _lazyHttpClient.Value;
}
}
#endif