refactor: build services with dependency injection
App registers the services, controllers, the main window and the pages in a container, and the navigation view asks it for each page. Pages get their controllers through the constructor instead of reading statics from App. SettingsStore takes over the current settings from App. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
65743279b1
commit
c6e9bf4e82
9 files changed
+112
-35
No files matched your search
@@ -0,0 +1,31 @@
|
||||
namespace Radiosender.Services;
|
||||
|
||||
/// <summary>
|
||||
/// The current <see cref="AppSettings"/> for the whole app. Loads them at startup and, on every save,
|
||||
/// writes the file and hands the minutes per hour to the schedule generator.
|
||||
/// </summary>
|
||||
public class SettingsStore
|
||||
{
|
||||
private readonly ScheduleGenerator _generator;
|
||||
private readonly string _path;
|
||||
|
||||
public SettingsStore(ScheduleGenerator generator, string path)
|
||||
{
|
||||
_generator = generator;
|
||||
_path = path;
|
||||
Current = AppSettings.Load(path);
|
||||
_generator.Options = Current.ToScheduleOptions();
|
||||
}
|
||||
|
||||
public AppSettings Current { get; private set; }
|
||||
|
||||
/// <summary>Stores the settings and applies them: alerts at once, minutes per hour from the next plan on.</summary>
|
||||
/// <exception cref="System.IO.IOException">The settings file cannot be written.</exception>
|
||||
/// <exception cref="UnauthorizedAccessException">The settings file cannot be written.</exception>
|
||||
public void Save(AppSettings settings)
|
||||
{
|
||||
settings.Save(_path);
|
||||
Current = settings;
|
||||
_generator.Options = settings.ToScheduleOptions();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user