SharedHttpClient Class

Namespace
Kampute.HttpClient.Utilities
Assembly
  • Kampute.HttpClient.dll

Definition

Provides the HttpClient that instances of HttpRestClient share by default.
public static class SharedHttpClient
Inheritance

Remarks

Sharing one HttpClient lets all clients reuse the same connections. The HttpClient is created when the first reference is acquired, and disposed when the last reference is released; a later reference creates a new one with Factory.

Properties

Factory

Gets or sets the function that creates the shared HttpClient.
public static Func<HttpClient> Factory { get; set; }

Property Value

Func<HttpClient>
The function that creates the shared HttpClient, or null to create one with its parameterless constructor.

Exceptions

InvalidOperationException
Thrown if the value is set after the first reference has been acquired.

Remarks

Set this property at application startup, before any HttpRestClient is created with the shared HttpClient, to configure its handler, proxy, or timeout.

ReferenceCount

Gets the number of active references to the shared HttpClient.
public static int ReferenceCount { get; }

Property Value

int
The number of active references.

Methods

AcquireReference()

Acquires a reference to the shared HttpClient.
public static SharedDisposable<HttpClient>.Reference AcquireReference()

Returns

SharedDisposable<HttpClient>.Reference
A SharedDisposable<T>.Reference to the shared HttpClient, which releases it when it is disposed.