mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
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:
@@ -16,13 +16,21 @@ final class CreateRoomScreenViewModelTests {
|
||||
var clientProxy: ClientProxyMock!
|
||||
var spaceService: SpaceServiceProxyMock!
|
||||
var userSession: UserSessionMock!
|
||||
|
||||
|
||||
private let appSettings: AppSettings
|
||||
private let analytics: AnalyticsService
|
||||
|
||||
private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([])
|
||||
|
||||
var context: CreateRoomScreenViewModel.Context {
|
||||
viewModel.context
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
appSettings = AppSettings()
|
||||
analytics = .mock(settings: appSettings)
|
||||
}
|
||||
|
||||
deinit {
|
||||
AppSettings.resetAllSettings()
|
||||
viewModel = nil
|
||||
@@ -82,14 +90,14 @@ final class CreateRoomScreenViewModelTests {
|
||||
spaceServiceConfiguration: .init(spaceRoomLists: ["1": .init()])))
|
||||
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
|
||||
userSession = UserSessionMock(.init(clientProxy: clientProxy))
|
||||
ServiceLocator.shared.settings.knockingEnabled = true
|
||||
appSettings.knockingEnabled = true
|
||||
let viewModel = CreateRoomScreenViewModel(isSpace: true,
|
||||
spaceSelectionMode: .none,
|
||||
shouldShowCancelButton: false,
|
||||
userSession: userSession,
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
analytics: analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
appSettings: appSettings)
|
||||
self.viewModel = viewModel
|
||||
|
||||
// Given a form with a blank topic.
|
||||
@@ -332,14 +340,14 @@ final class CreateRoomScreenViewModelTests {
|
||||
clientProxy.spaceService = spaceService
|
||||
clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) }
|
||||
userSession = UserSessionMock(.init(clientProxy: clientProxy))
|
||||
ServiceLocator.shared.settings.knockingEnabled = true
|
||||
appSettings.knockingEnabled = true
|
||||
let viewModel = CreateRoomScreenViewModel(isSpace: isSpace,
|
||||
spaceSelectionMode: spacesSelectionMode,
|
||||
shouldShowCancelButton: false,
|
||||
userSession: userSession,
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
analytics: analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
appSettings: appSettings)
|
||||
self.viewModel = viewModel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user