Files
Radio/src/Radiosender/App.xaml.cs
T
fraujulianandClaude Fable 5.2 d73b9b507f feat(import): add the Internet Archive as a music provider
Searches Creative Commons licensed MP3 audio. A search result there is an
item with several files, so the file list of each item is fetched too and
every MP3 becomes one result. Query operators are removed from the search
words, so they cannot change the license filter.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 15:09:36 +01:00

74 lines
3.3 KiB
C#

using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Radiosender.Controllers;
using Radiosender.Services;
using Radiosender.Views;
using Radiosender.Views.Pages;
namespace Radiosender;
/// <summary>Composition root: wires every service, controller and page once, at startup.</summary>
public partial class App : Application
{
private ServiceProvider? _services;
private static ServiceProvider BuildServices()
{
var services = new ServiceCollection();
// One instance each for the whole app. The schedule controller in particular must be shared,
// so a running broadcast keeps going while the user switches pages.
services.AddSingleton(_ => new SongRepository(SongRepository.DefaultDatabasePath));
services.AddSingleton(_ => new ScheduleGenerator());
services.AddSingleton(provider => new SettingsStore(provider.GetRequiredService<ScheduleGenerator>(), AppSettings.DefaultPath));
services.AddSingleton(_ => new PlaybackEngine());
services.AddSingleton(provider => new ScheduleController(
provider.GetRequiredService<SongRepository>(),
provider.GetRequiredService<ScheduleGenerator>(),
provider.GetRequiredService<PlaybackEngine>(),
() => DateTime.Now));
// One HttpClient for all providers and downloads.
services.AddSingleton(_ =>
{
var http = new System.Net.Http.HttpClient { Timeout = TimeSpan.FromSeconds(20) };
http.DefaultRequestHeaders.UserAgent.ParseAdd("Radiosender/1.0");
return http;
});
// Music providers: add a line here for each new IMusicProvider; the import page lists them all.
services.AddSingleton<IMusicProvider, OpenverseProvider>();
services.AddSingleton<IMusicProvider, InternetArchiveProvider>();
services.AddSingleton(provider => new TrackDownloader(provider.GetRequiredService<System.Net.Http.HttpClient>(), TrackDownloader.DefaultMusicFolder));
services.AddSingleton<OnlineImportController>();
services.AddSingleton(provider => new SongImportService(provider.GetRequiredService<SongRepository>(), SongImportService.DefaultMusicDirectory));
services.AddSingleton<UploadController>();
services.AddSingleton<LibraryController>();
// Pages are created anew on every navigation, as before; they hold only view state.
services.AddSingleton<MainWindow>();
services.AddTransient<SchedulePage>();
services.AddTransient<LibraryPage>();
services.AddTransient<ImportPage>();
services.AddTransient<SettingsPage>();
return services.BuildServiceProvider();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
_services = BuildServices();
// Loads the settings and gives the generator its minutes per hour before the first plan.
_services.GetRequiredService<SettingsStore>();
// Follow the Windows setting: light, dark or a high-contrast theme.
Wpf.Ui.Appearance.ApplicationThemeManager.ApplySystemTheme();
_services.GetRequiredService<MainWindow>().Show();
}
protected override void OnExit(ExitEventArgs e)
{
_services?.GetRequiredService<ScheduleController>().Stop();
_services?.Dispose();
base.OnExit(e);
}
}