feat: utilize IHttpClientFactory for improved HTTP client management
- Replaced direct `HttpClient` dependencies with `IHttpClientFactory` in `GithubService`, `ForgejoService`, and `ReleaseAssetDownloadService`. - Added DI-configured HTTP client registrations for GitHub, Forgejo, and asset downloads in `Program.cs`. - Consolidated HTTP client setup to enhance maintainability, configurability, and resource lifecycle management.
This commit is contained in:
1 parent
3b644de2d5
commit
8db845f27a
4 files changed
+35
-19
No files matched your search
@@ -6,16 +6,17 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ForgejoReleaseSync.Services;
|
||||
|
||||
public class GithubService(HttpClient httpClient, ILogger<GithubService> logger)
|
||||
public class GithubService(IHttpClientFactory httpClientFactory, ILogger<GithubService> logger)
|
||||
{
|
||||
public async Task<List<GithubReleaseResponseDto>> FetchRepoReleasesAsync(
|
||||
string owner, string repo, CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpClient = httpClientFactory.CreateClient("github");
|
||||
|
||||
using var response = await httpClient.GetAsync(
|
||||
new Uri($"https://api.github.com/repos/{owner}/{repo}/releases?per_page=3&page=1"),
|
||||
token);
|
||||
$"repos/{owner}/{repo}/releases?per_page=3&page=1", token);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(token);
|
||||
|
||||
Reference in new issue
Block a user