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:
mahdium committed 2026-11-04 17:05:41 +03:30
1 parent 3b644de2d5
commit 8db845f27a
4 files changed
+35 -19

No files matched your search

+3 -1
View File
@@ -2,12 +2,14 @@ using Microsoft.Extensions.Logging;
namespace ForgejoReleaseSync.Services;
public class ReleaseAssetDownloadService(HttpClient httpClient, ILogger<ReleaseAssetDownloadService> logger)
public class ReleaseAssetDownloadService(IHttpClientFactory httpClientFactory, ILogger<ReleaseAssetDownloadService> logger)
{
public async Task<string> DownloadReleaseAssetAsync(Uri url, CancellationToken token = default)
{
try
{
var httpClient = httpClientFactory.CreateClient("asset-download");
var fileName = Path.GetFileName(url.AbsoluteUri);
var filePath = Path.Combine(Path.GetTempPath(), fileName);