Created
October 7, 2021 15:21
-
-
Save bigMOTOR/73a2863c0899ef843979db249fd6e429 to your computer and use it in GitHub Desktop.
2021-10-02_Article_ComposableContextsArchitecture_3.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Context | |
private final class UserScreenContext: UserRepositoryTypeHolderType { | |
let userRepository: UserRepositoryType | |
init(userRepository: UserRepositoryType) { | |
self.userRepository = userRepository | |
} | |
} | |
extension UserScreenContext: ObserveUserNameUseCase {} | |
extension UserScreenContext: SignOutUseCase {} | |
/// Here is an example of how we are constructing everything with DependencyContainer (Dip framework implementation) | |
enum UserScreenComposition { | |
static func configure(_ container: DependencyContainer) { | |
// UseCases | |
container.register { | |
UserScreenContext(userRepository: $0, ...) | |
} | |
.implements(UserScreenViewModel.UseCases.self) | |
// View Models | |
container.register { | |
UserScreenViewModel(useCases: $0) | |
} | |
// View Controller | |
container | |
.register(storyboardType: UserController.self, tag: "UserScreen") | |
.resolvingProperties { container, controller in | |
controller.viewModel = try container.resolve() | |
} | |
DependencyContainer.uiContainers.append(container) | |
} | |
} | |
extension UserController: StoryboardInstantiatable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment