Refactor AppServices into assembly, feature facades, and lifecycle coordinator.

Extract dependency wiring and session lifecycle from the container and RootViewController, split NetworkBundle by domain, and add module-level feature services while keeping flat accessors for compatibility.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 09:32:44 +08:00
parent 1a6d4a1791
commit 0d8f97417b
11 changed files with 686 additions and 197 deletions

View File

@ -0,0 +1,84 @@
//
// AppServicesAssembly.swift
// suixinkan
//
// Created by Codex on 2026/6/29.
//
import Foundation
@MainActor
/// `AppServices`
struct AppServicesAssembly {
private let apiClient: APIClient
private let tokenStore: SessionTokenStore
private let snapshotStore: AccountSnapshotStore
private let preferencesStore: AppPreferencesStore
///
init() {
apiClient = APIClient()
tokenStore = SessionTokenStore()
snapshotStore = AccountSnapshotStore()
preferencesStore = AppPreferencesStore()
}
///
init(
apiClient: APIClient,
tokenStore: SessionTokenStore,
snapshotStore: AccountSnapshotStore,
preferencesStore: AppPreferencesStore
) {
self.apiClient = apiClient
self.tokenStore = tokenStore
self.snapshotStore = snapshotStore
self.preferencesStore = preferencesStore
}
/// `AppServices`
func makeDependencies() -> AppServicesDependencies {
AppServicesDependencies(
session: makeSessionBundle(),
context: AppContextBundle(
accountContext: AccountContext(),
permissionContext: PermissionContext(),
scenicSpotContext: ScenicSpotContext()
),
network: NetworkBundle(apiClient: apiClient),
ui: UIFeedbackBundle(
toastCenter: ToastCenter(),
globalLoading: GlobalLoadingCenter()
),
runtime: AppRuntimeBundle(scenicQueueRuntime: ScenicQueueRuntime.shared),
appNavigator: AppNavigator()
)
}
/// 退
private func makeSessionBundle() -> SessionBundle {
SessionBundle(
appSession: AppSession(),
authSessionCoordinator: AuthSessionCoordinator(
tokenStore: tokenStore,
snapshotStore: snapshotStore,
preferencesStore: preferencesStore
),
sessionBootstrapper: SessionBootstrapper(
tokenStore: tokenStore,
snapshotStore: snapshotStore
)
)
}
}
@MainActor
/// `AppServices`
struct AppServicesDependencies {
let session: SessionBundle
let context: AppContextBundle
let network: NetworkBundle
let ui: UIFeedbackBundle
let runtime: AppRuntimeBundle
let appNavigator: AppNavigator
}