Files
suixinkan_ios_uikit/suixinkan_ios/App/AppServices.swift
汉秋 0d8f97417b 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>
2026-06-29 09:32:44 +08:00

72 lines
2.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppServices.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
import Foundation
@MainActor
/// ViewModel ViewController API
final class AppServices {
static let shared = AppServices()
let session: SessionBundle
let context: AppContextBundle
let network: NetworkBundle
let ui: UIFeedbackBundle
let runtime: AppRuntimeBundle
let appNavigator: AppNavigator
///
private convenience init() {
self.init(assembly: AppServicesAssembly())
}
/// mock `APIClient`
convenience init(
apiClient: APIClient,
tokenStore: SessionTokenStore = SessionTokenStore(),
snapshotStore: AccountSnapshotStore = AccountSnapshotStore(),
preferencesStore: AppPreferencesStore = AppPreferencesStore()
) {
self.init(
assembly: AppServicesAssembly(
apiClient: apiClient,
tokenStore: tokenStore,
snapshotStore: snapshotStore,
preferencesStore: preferencesStore
)
)
}
/// 使 bundle
private init(assembly: AppServicesAssembly) {
let dependencies = assembly.makeDependencies()
session = dependencies.session
context = dependencies.context
network = dependencies.network
ui = dependencies.ui
runtime = dependencies.runtime
appNavigator = dependencies.appNavigator
bindAuthTokenProvider()
}
/// UIKit
func configurePushNotifications() {
PushNotificationManager.shared.configure(
api: pushAPI,
session: appSession,
navigator: appNavigator
)
}
/// `APIClient` `AppSession` token
private func bindAuthTokenProvider() {
apiClient.bindAuthTokenProvider { [unowned self] in
appSession.token
}
}
}