diff --git a/Manager.App/DependencyInjection.cs b/Manager.App/DependencyInjection.cs index cb62380..ae958d3 100644 --- a/Manager.App/DependencyInjection.cs +++ b/Manager.App/DependencyInjection.cs @@ -25,9 +25,11 @@ public static class DependencyInjection options.UseSqlite($"Data Source={dbPath}"); }); - builder.Services.AddScoped(); - + + builder.Services.AddSingleton(); builder.Services.AddHostedService(); + + builder.Services.AddScoped(); } public static void SetupSettings(this WebApplicationBuilder builder) diff --git a/Manager.App/Services/System/ClientManager.cs b/Manager.App/Services/System/ClientManager.cs index 2171a67..f19887f 100644 --- a/Manager.App/Services/System/ClientManager.cs +++ b/Manager.App/Services/System/ClientManager.cs @@ -6,15 +6,19 @@ using Manager.YouTube; namespace Manager.App.Services.System; -public class ClientManager : BackgroundService +public class ClientManager(IServiceScopeFactory scopeFactory, HostedServiceConnector serviceConnector) : BackgroundService { private readonly List _clients = []; private CancellationToken _cancellationToken; + private ILibraryService? _libraryService; protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + serviceConnector.RegisterService(this); _cancellationToken = stoppingToken; stoppingToken.Register(CancellationRequested); + using var scope = scopeFactory.CreateScope(); + _libraryService = scope.ServiceProvider.GetRequiredService(); } private void CancellationRequested() diff --git a/Manager.App/Services/System/HostedServiceConnector.cs b/Manager.App/Services/System/HostedServiceConnector.cs new file mode 100644 index 0000000..a08d436 --- /dev/null +++ b/Manager.App/Services/System/HostedServiceConnector.cs @@ -0,0 +1,11 @@ +namespace Manager.App.Services.System; + +public class HostedServiceConnector +{ + private readonly List _hostedServices = []; + + public void RegisterService(IHostedService service) + { + _hostedServices.Add(service); + } +} \ No newline at end of file