using YKanBan.Storage.AppData; using YKanBan.Storage.Workspace; namespace YKanBan.Services; /// /// Composition root for the whole process: owns the loaded configuration and /// the single open workspace session. The configuration is persisted once at /// shutdown, and only when this session changed it; the session (lock plus connection) lives until disposal. /// public sealed class AppServices : IDisposable { /// /// Loads the configuration and prepares the service graph. /// public AppServices() { ConfigStore = new AppConfigStore(AppDataPaths.AppConfigJsonPath); Config = ConfigStore.Load(); } /// /// Gets the mutable application configuration, persisted at shutdown. /// public AppConfig Config { get; } /// /// Gets the store backing app.json. /// public AppConfigStore ConfigStore { get; } /// /// Gets the open workspace session, or while no /// workspace is open (for example on an error page). /// public WorkspaceSession? Session { get; private set; } /// /// Opens a workspace, acquiring its exclusive lock and connection. /// /// The workspace folder to open. /// The open session. /// The folder has no .ykanban structure. /// Another instance already holds the lock. public WorkspaceSession OpenWorkspace(string folderPath) { Session = WorkspaceSession.Open(folderPath); return Session; } /// /// Persists the configuration when this session changed a setting; called once at shutdown. /// public void SaveConfiguration() => ConfigStore.SaveIfChanged(Config); /// /// Releases the workspace session, if any. /// public void Dispose() => Session?.Dispose(); }