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:
84
suixinkan_ios/App/AppServicesAssembly.swift
Normal file
84
suixinkan_ios/App/AppServicesAssembly.swift
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user