Files
av-parser/src/AvParser.UI/DependencyInjection/UiServiceCollectionExtensions.cs
T
Leonid Pershin eb5061ee23 Refactor media source handling and update collection options
- Updated `IMediaSourceCatalog` to support user-added media sources, allowing dynamic editing and management of sources.
- Removed the `UrlListSource` class as its functionality is now integrated into the new catalog structure.
- Enhanced `CollectOptions` to default `RequireProxy` to true, ensuring stricter handling of proxy requirements.
- Improved error handling in `ParseError` to include a `Subject` field for better context on failures.
- Adjusted dependency injection to reflect changes in media source management, removing old source registrations.
- Introduced background proxy checks to ensure a more robust proxy pool management during collection processes.

These changes streamline the media collection process and improve the overall user experience by providing clearer error reporting and more flexible source management.
2026-08-15 14:20:06 +03:00

93 lines
4.3 KiB
C#

using AvParser.Core.Collecting;
using AvParser.Core.Proxies;
using AvParser.Core.Settings;
using AvParser.Infrastructure.Proxies;
using AvParser.Infrastructure.Storage;
using AvParser.UI.Media;
using AvParser.UI.Navigation;
using AvParser.UI.Services;
using AvParser.UI.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog.Core;
namespace AvParser.UI.DependencyInjection;
/// <summary>Composition root for the presentation layer.</summary>
public static class UiServiceCollectionExtensions
{
/// <summary>Registers the view locator, shell services and every page.</summary>
/// <remarks>
/// Pages are registered twice on purpose: once under their concrete type (so tests and other
/// pages can ask for one specifically) and once under <see cref="PageViewModel"/> in the order
/// they should appear in the navigation rail.
/// </remarks>
public static IServiceCollection AddAvParserUI(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.AddSingleton<ViewLocator>();
services.AddSingleton<IThumbnailCache>(static sp => new ThumbnailCache(
sp.GetRequiredService<IAppPaths>(),
sp.GetRequiredService<ILogger<ThumbnailCache>>()
));
services.AddSingleton<IFolderPicker, FolderPicker>();
services.AddSingleton<IThemeService, ThemeService>();
services.AddSingleton<ILocalizationService, LocalizationService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<DashboardViewModel>(static sp => new DashboardViewModel(
sp.GetRequiredService<IMediaSourceCatalog>(),
sp.GetRequiredService<IAppPaths>(),
sp.GetRequiredService<IProxyPool>(),
sp
));
services.AddSingleton<SettingsViewModel>(static sp => new SettingsViewModel(
sp.GetRequiredService<ISettingsService>(),
sp.GetRequiredService<IThemeService>(),
sp.GetRequiredService<IAppPaths>(),
sp.GetRequiredService<LoggingLevelSwitch>(),
sp.GetRequiredService<IProxyPool>(),
sp.GetRequiredService<ILocalizationService>(),
sp.GetRequiredService<IFolderPicker>()
));
services.AddSingleton<CollectViewModel>(static sp => new CollectViewModel(
sp.GetRequiredService<IMediaSourceCatalog>(),
sp.GetRequiredService<ISettingsService>(),
sp.GetRequiredService<IProxyPool>(),
sp.GetRequiredService<ICollectRunner>(),
sp.GetRequiredService<IMediaStore>(),
sp.GetRequiredService<IThumbnailCache>(),
sp,
sp.GetRequiredService<ILogger<CollectViewModel>>()
));
services.AddSingleton<GalleryViewModel>(static sp => new GalleryViewModel(
sp.GetRequiredService<IMediaStore>(),
sp.GetRequiredService<IThumbnailCache>(),
sp.GetRequiredService<ILogger<GalleryViewModel>>()
));
services.AddSingleton<ProxiesViewModel>(static sp => new ProxiesViewModel(
sp.GetRequiredService<IProxyPool>(),
sp.GetRequiredService<IMutableProxySource>(),
sp.GetRequiredService<IProxyPoolLoader>(),
sp.GetRequiredService<ILogger<ProxiesViewModel>>()
));
services.AddSingleton<AboutViewModel>();
// Order here is the order of the navigation rail; the first entry is the landing page.
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<DashboardViewModel>());
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<CollectViewModel>());
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<GalleryViewModel>());
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<ProxiesViewModel>());
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<SettingsViewModel>());
services.AddSingleton<PageViewModel>(static sp => sp.GetRequiredService<AboutViewModel>());
services.AddSingleton<ShellViewModel>(static sp => new ShellViewModel(
sp.GetRequiredService<INavigationService>(),
sp.GetRequiredService<IThemeService>()
));
return services;
}
}