File tree 3 files changed +32
-0
lines changed
3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace HttpClientFactory ;
4
4
5
+ /// <summary>
6
+ /// Represents a cached implementation of the IHttpClientFactory interface.
7
+ /// </summary>
5
8
public class CachedHttpClientFactory : IHttpClientFactory
6
9
{
7
10
private readonly IHttpClientFactory _httpClientFactory ;
8
11
private readonly Dictionary < int , HttpClient > _cache = new ( ) ;
9
12
13
+ /// <summary>
14
+ /// Initializes a new instance of the CachedHttpClientFactory class with the specified IHttpClientFactory implementation.
15
+ /// </summary>
16
+ /// <param name="httpClientFactory">An instance of IHttpClientFactory used to create HttpClient instances.</param>
10
17
public CachedHttpClientFactory ( IHttpClientFactory httpClientFactory ) =>
11
18
_httpClientFactory = httpClientFactory ;
12
19
20
+ /// <summary>
21
+ /// Creates an HttpClient instance with the specified web proxy. If the same web proxy has been used before, a cached instance will be returned.
22
+ /// </summary>
23
+ /// <param name="webProxy">The web proxy to be used by the HttpClient.</param>
24
+ /// <returns>An instance of HttpClient configured with the provided web proxy.</returns>
13
25
public HttpClient CreateClientWithProxy ( IWebProxy webProxy )
14
26
{
15
27
var key = webProxy . GetHashCode ( ) ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace HttpClientFactory ;
4
4
5
+ /// <summary>
6
+ /// Represents a concrete implementation of the IHttpClientFactory interface.
7
+ /// </summary>
5
8
public class HClientFactory : IHttpClientFactory
6
9
{
7
10
private readonly Func < HttpClientHandler > _makeHandler ;
8
11
12
+ /// <summary>
13
+ /// Initializes a new instance of the HClientFactory class with the specified HttpClientHandler factory function.
14
+ /// </summary>
15
+ /// <param name="makeHandler">A factory function that creates instances of HttpClientHandler.</param>
9
16
public HClientFactory ( Func < HttpClientHandler > makeHandler ) =>
10
17
_makeHandler = makeHandler ;
11
18
19
+ /// <summary>
20
+ /// Creates an HttpClient instance with the specified web proxy.
21
+ /// </summary>
22
+ /// <param name="webProxy">The web proxy to be used by the HttpClient.</param>
23
+ /// <returns>An instance of HttpClient configured with the provided web proxy.</returns>
12
24
public HttpClient CreateClientWithProxy ( IWebProxy webProxy )
13
25
{
14
26
var handler = _makeHandler ( ) ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace HttpClientFactory ;
4
4
5
+ /// <summary>
6
+ /// Represents a factory for creating HttpClient instances.
7
+ /// </summary>
5
8
public interface IHttpClientFactory
6
9
{
10
+ /// <summary>
11
+ /// Creates an HttpClient instance with the specified web proxy.
12
+ /// </summary>
13
+ /// <param name="webProxy">The web proxy to be used by the HttpClient.</param>
14
+ /// <returns>An instance of HttpClient configured with the provided web proxy.</returns>
7
15
HttpClient CreateClientWithProxy ( IWebProxy webProxy ) ;
8
16
}
You can’t perform that action at this time.
0 commit comments