Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
soenneker authored Nov 16, 2023
1 parent 7735435 commit 36b776c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Utils.HttpClientCache
### Providing thread-safe singleton HttpClients

### Why
### Why?

'Long-lived' `HttpClient` static/singleton instances are the recommended use pattern in .NET. Avoid the unnecessary overhead of `IHttpClientFactory`, and _definitely_ avoid creating a new `HttpClient` instance per request.
'Long-lived' `HttpClient` static/singleton instances is the recommended use pattern in .NET. Avoid the unnecessary overhead of `IHttpClientFactory`, and _definitely_ avoid creating a new `HttpClient` instance per request.

See [Guidelines for using HttpClient](https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines)
`HttpClientCache` provides a thread-safe singleton `HttpClient` instance per key via dependency injection. `HttpClient`s are created lazily, and disposed on application shutdown (or manually if you want).

`HttpClientCache` provides a thread-safe singleton `HttpClient` instance per key. The `HttpClient` is created on first access and disposed on application shutdown (or manual removal/disposal).
See [Guidelines for using HttpClient](https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines)

## Installation

```
Install-Package Soenneker.Utils.HttpClientCache
```


## Usage

1. Register the interop within DI (`Program.cs`).
Expand Down Expand Up @@ -57,4 +56,4 @@ public class TestClass
return responseString;
}
}
```
```

0 comments on commit 36b776c

Please sign in to comment.