fix: PlatformHttpClientFactory uses IServiceScopeFactory to avoid disposed DbContext in danmaku retry

PlatformHttpClientFactory was holding a direct ISystemSettingsService reference
(Scoped). When the danmaku connection's request scope ended, retry attempts failed
with ObjectDisposedException on LiveRecorderDbContext.

Changed to use IServiceScopeFactory to create a fresh scope on each CreateAsync call,
so the danmaku retry loop always gets a live DbContext.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
This commit is contained in:
2026-06-05 00:02:42 +08:00
co-authored by Claude Opus 4.8 noreply@anthropic.com
parent 24e5cf2a06
commit 524a053263
@@ -5,6 +5,7 @@ using LiveRecorder.Application.Common;
using LiveRecorder.Application.Abstractions.Settings;
using LiveRecorder.Application.Models.Settings;
using LiveRecorder.Domain.Enums;
using Microsoft.Extensions.DependencyInjection;
namespace LiveRecorder.Infrastructure.Services;
@@ -13,11 +14,11 @@ public sealed class PlatformHttpClientFactory
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(20);
private static readonly TimeSpan DefaultConnectTimeout = TimeSpan.FromSeconds(10);
private readonly ISystemSettingsService _systemSettingsService;
private readonly IServiceScopeFactory _serviceScopeFactory;
public PlatformHttpClientFactory(ISystemSettingsService systemSettingsService)
public PlatformHttpClientFactory(IServiceScopeFactory serviceScopeFactory)
{
_systemSettingsService = systemSettingsService;
_serviceScopeFactory = serviceScopeFactory;
}
public async Task<HttpClient> CreateAsync(
@@ -25,7 +26,9 @@ public sealed class PlatformHttpClientFactory
bool forceDirectConnection,
CancellationToken cancellationToken = default)
{
var settings = await _systemSettingsService.GetAsync(cancellationToken);
using var scope = _serviceScopeFactory.CreateScope();
var systemSettingsService = scope.ServiceProvider.GetRequiredService<ISystemSettingsService>();
var settings = await systemSettingsService.GetAsync(cancellationToken);
var proxy = forceDirectConnection ? null : BuildProxy(platform, settings);
var handler = new SocketsHttpHandler
{