Refactor AppServices into grouped bundles and document DI conventions.

Centralize dependency wiring with Session/Context/Network/UI/Runtime bundles, unify leaf ViewControllers on appServices, and add a test initializer with AppServicesTests.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 15:24:25 +08:00
parent d99a5b1bf8
commit 24a7339b68
10 changed files with 385 additions and 114 deletions

View File

@ -15,7 +15,6 @@ final class OperatingAreaViewController: UIViewController {
private lazy var blockReasonView = AppContentUnavailableView(title: "无法展示地图", systemImage: "mappin.slash")
private var dataSource: UITableViewDiffableDataSource<Int, String>!
private var services: AppServices { AppServices.shared }
/// UI
override func viewDidLoad() {
@ -112,12 +111,12 @@ final class OperatingAreaViewController: UIViewController {
private func scopeText() -> String {
switch viewModel.mode {
case .storeAdmin:
return services.accountContext.currentStore?.name ?? "当前店铺"
return appServices.accountContext.currentStore?.name ?? "当前店铺"
case .scenicAdmin:
return services.accountContext.currentScenic?.name ?? "当前景区"
return appServices.accountContext.currentScenic?.name ?? "当前景区"
case nil:
return services.accountContext.currentScenic?.name
?? services.accountContext.currentStore?.name
return appServices.accountContext.currentScenic?.name
?? appServices.accountContext.currentStore?.name
?? "未选择业务范围"
}
}
@ -130,16 +129,16 @@ final class OperatingAreaViewController: UIViewController {
}
private func reload(showLoading: Bool) async {
if showLoading { services.globalLoading.show() }
defer { if showLoading { services.globalLoading.hide() } }
if showLoading { appServices.globalLoading.show() }
defer { if showLoading { appServices.globalLoading.hide() } }
await viewModel.reload(
api: services.operatingAreaAPI,
accountContext: services.accountContext,
permissionContext: services.permissionContext
api: appServices.operatingAreaAPI,
accountContext: appServices.accountContext,
permissionContext: appServices.permissionContext
)
if let message = viewModel.errorMessage {
services.toastCenter.show(message)
appServices.toastCenter.show(message)
}
}
}