Table of Contents

Class SharedHttpClient

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

Provides a singleton-like access to a shared HttpClient instance across the application.

public static class SharedHttpClient
Inheritance
SharedHttpClient
Inherited Members

Remarks

This static class manages the lifecycle of a single HttpClient instance. It ensures efficient resource usage by allowing the HttpClient to be reused throughout the application. The HttpClient is managed as a shared disposable resource, which means it is only disposed when no longer in use by any part of the application.

Properties

Factory

Gets or sets the factory method used to create the HttpClient instance.

public static Func<HttpClient>? Factory { get; set; }

Property Value

Func<HttpClient>

A function that returns an HttpClient when invoked.

Remarks

This property allows for the customization of the HttpClient creation process. Changing this property after the HttpClient has been created will throw an InvalidOperationException to prevent inconsistent states by modifying the factory method post creation.

Exceptions

InvalidOperationException

Thrown if attempting to change the factory after the HttpClient instance has been created.

ReferenceCount

Gets the current number of active references to the shared HttpClient instance.

public static int ReferenceCount { get; }

Property Value

int

The number of active references.

Methods

AcquireReference()

Acquires a reference to the shared HttpClient instance.

public static SharedDisposable<HttpClient>.Reference AcquireReference()

Returns

SharedDisposable<HttpClient>.Reference

A SharedDisposable<T>.Reference that manages the lifetime of the shared HttpClient.