Replace the ServiceLocator with direct dependency injection (#5548)

Removes the ServiceLocator singleton and instead directly injects the dependencies it was holding for more control over instantiation of the various component subtrees and better visibility over how they're being used.
This commit is contained in:
Michael
2026-05-14 01:45:49 -05:00
committed by GitHub
parent f70182d09a
commit ff5dcb040d
108 changed files with 971 additions and 729 deletions
@@ -17,17 +17,10 @@ class UnitTestsAppCoordinator: AppCoordinatorProtocol {
init(appDelegate: AppDelegate) {
windowManager = WindowManager(appDelegate: appDelegate)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorControllerMock.default)
AppSettings.configureWithSuiteName("io.element.elementx.unittests")
AppSettings.resetAllSettings()
ServiceLocator.shared.register(appSettings: AppSettings())
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: ServiceLocator.shared.settings))
// As the tests take advantage of Rust's ability to redirect the log files, there is
// often some debris left from the previous run, so we wipe the entire directory.
// This is an NOT an advised way to delete logs in production, `Tracing.deleteLogFiles`