Skip to content

Commit

Permalink
[Add/#7] DIContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-seonwoo committed Jun 7, 2024
1 parent 69bda45 commit 9e7c121
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
16 changes: 16 additions & 0 deletions Tving-Clone/Tving-Clone/Application/AppDIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AppDIContainer.swift
// Tving-Clone
//
// Created by Seonwoo Kim on 6/7/24.
//

import Foundation

final class AppDIContainer {

func makeContentSceneDIContainer() -> ContentDIContainer {
let dependencies = ContentDIContainer.Dependencies(contentDataSource: ContentDataSource())
return ContentDIContainer(dependencies: dependencies)
}
}
41 changes: 41 additions & 0 deletions Tving-Clone/Tving-Clone/Application/ContentDIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DIConteainer.swift
// Tving-Clone
//
// Created by Seonwoo Kim on 6/7/24.
//

import Foundation

final class ContentDIContainer {

struct Dependencies {
let contentDataSource: ContentDataSource
}

private let dependencies: Dependencies

init(dependencies: Dependencies) {
self.dependencies = dependencies
}

func makeContentRepository() -> ContentRepository {
return DefaultContentRepository(contentDataSource: dependencies.contentDataSource)
}

func makeContentUseCase() -> ContentUseCase {
return DefaultContentUseCase(repository: makeContentRepository())
}

func makeMainContentViewModel() -> MainContentViewModel {
return MainContentViewModel(contentUseCase: makeContentUseCase())
}

func makeMainContentViewController() -> MainContentViewController {
return MainContentViewController(viewModel: makeMainContentViewModel())
}

func makeTabBarController() -> TabBarController {
return TabBarController(mainContentViewModel: makeMainContentViewModel())
}
}
9 changes: 3 additions & 6 deletions Tving-Clone/Tving-Clone/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
let appDIContainer = AppDIContainer()

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }

let contentDataSource = ContentDataSource()
let contentRepository = DefaultContentRepository(contentDataSource: contentDataSource)
let contentUseCase = DefaultContentUseCase(repository: contentRepository)
let mainContentViewModel = MainContentViewModel(contentUseCase: contentUseCase)
let mainContentVC = MainContentViewController(viewModel: mainContentViewModel)
let tabBarController = TabBarController(mainContentViewModel: mainContentViewModel)
let contentSceneDIContainer = appDIContainer.makeContentSceneDIContainer()
let tabBarController = contentSceneDIContainer.makeTabBarController()

window = UIWindow(windowScene: windowScene)
window?.rootViewController = UINavigationController(rootViewController: tabBarController)
Expand Down

0 comments on commit 9e7c121

Please sign in to comment.