[CHANGE] DI fixes
This commit is contained in:
@@ -25,9 +25,11 @@ public static class DependencyInjection
|
|||||||
options.UseSqlite($"Data Source={dbPath}");
|
options.UseSqlite($"Data Source={dbPath}");
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddScoped<ILibraryService, LibraryService>();
|
|
||||||
|
builder.Services.AddSingleton<HostedServiceConnector>();
|
||||||
builder.Services.AddHostedService<ClientManager>();
|
builder.Services.AddHostedService<ClientManager>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<ILibraryService, LibraryService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetupSettings(this WebApplicationBuilder builder)
|
public static void SetupSettings(this WebApplicationBuilder builder)
|
||||||
|
@@ -6,15 +6,19 @@ using Manager.YouTube;
|
|||||||
|
|
||||||
namespace Manager.App.Services.System;
|
namespace Manager.App.Services.System;
|
||||||
|
|
||||||
public class ClientManager : BackgroundService
|
public class ClientManager(IServiceScopeFactory scopeFactory, HostedServiceConnector serviceConnector) : BackgroundService
|
||||||
{
|
{
|
||||||
private readonly List<YouTubeClient> _clients = [];
|
private readonly List<YouTubeClient> _clients = [];
|
||||||
private CancellationToken _cancellationToken;
|
private CancellationToken _cancellationToken;
|
||||||
|
private ILibraryService? _libraryService;
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
|
serviceConnector.RegisterService(this);
|
||||||
_cancellationToken = stoppingToken;
|
_cancellationToken = stoppingToken;
|
||||||
stoppingToken.Register(CancellationRequested);
|
stoppingToken.Register(CancellationRequested);
|
||||||
|
using var scope = scopeFactory.CreateScope();
|
||||||
|
_libraryService = scope.ServiceProvider.GetRequiredService<ILibraryService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CancellationRequested()
|
private void CancellationRequested()
|
||||||
|
11
Manager.App/Services/System/HostedServiceConnector.cs
Normal file
11
Manager.App/Services/System/HostedServiceConnector.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Manager.App.Services.System;
|
||||||
|
|
||||||
|
public class HostedServiceConnector
|
||||||
|
{
|
||||||
|
private readonly List<IHostedService> _hostedServices = [];
|
||||||
|
|
||||||
|
public void RegisterService(IHostedService service)
|
||||||
|
{
|
||||||
|
_hostedServices.Add(service);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user