Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Swinject #1

Open
wants to merge 1 commit into
base: 005-mengganti-callback-dengan-combine
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions TheMealsApp/TheMealsApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
2AC96399292CB25E0061B65A /* LocaleDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AC96398292CB25E0061B65A /* LocaleDataSource.swift */; };
2AC9639B292CB2770061B65A /* CategoryEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AC9639A292CB2770061B65A /* CategoryEntity.swift */; };
2AC9639F292CB8270061B65A /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 2AC9639E292CB8270061B65A /* CachedAsyncImage */; };
E2800F892C4A70AB003D93A6 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = E2800F882C4A70AB003D93A6 /* Swinject */; };
E2800F8B2C4A70AB003D93A6 /* Swinject-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = E2800F8A2C4A70AB003D93A6 /* Swinject-Dynamic */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -69,7 +71,9 @@
buildActionMask = 2147483647;
files = (
2AC96396292CB18A0061B65A /* RealmSwift in Frameworks */,
E2800F892C4A70AB003D93A6 /* Swinject in Frameworks */,
2AC9639F292CB8270061B65A /* CachedAsyncImage in Frameworks */,
E2800F8B2C4A70AB003D93A6 /* Swinject-Dynamic in Frameworks */,
2AC96394292CB18A0061B65A /* Realm in Frameworks */,
2A9276B0292CAA7B00C30767 /* Alamofire in Frameworks */,
);
Expand Down Expand Up @@ -337,6 +341,8 @@
2AC96393292CB18A0061B65A /* Realm */,
2AC96395292CB18A0061B65A /* RealmSwift */,
2AC9639E292CB8270061B65A /* CachedAsyncImage */,
E2800F882C4A70AB003D93A6 /* Swinject */,
E2800F8A2C4A70AB003D93A6 /* Swinject-Dynamic */,
);
productName = TheMealsApp;
productReference = 2A9D452B292C805D008FABEB /* TheMealsApp.app */;
Expand Down Expand Up @@ -370,6 +376,7 @@
2A9276AE292CAA7B00C30767 /* XCRemoteSwiftPackageReference "Alamofire" */,
2AC96392292CB18A0061B65A /* XCRemoteSwiftPackageReference "realm-swift" */,
2AC9639D292CB8270061B65A /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */,
E2800F872C4A70AB003D93A6 /* XCRemoteSwiftPackageReference "Swinject" */,
);
productRefGroup = 2A9D452C292C805D008FABEB /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -642,6 +649,14 @@
minimumVersion = 2.0.0;
};
};
E2800F872C4A70AB003D93A6 /* XCRemoteSwiftPackageReference "Swinject" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Swinject/Swinject";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.9.1;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -665,6 +680,16 @@
package = 2AC9639D292CB8270061B65A /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */;
productName = CachedAsyncImage;
};
E2800F882C4A70AB003D93A6 /* Swinject */ = {
isa = XCSwiftPackageProductDependency;
package = E2800F872C4A70AB003D93A6 /* XCRemoteSwiftPackageReference "Swinject" */;
productName = Swinject;
};
E2800F8A2C4A70AB003D93A6 /* Swinject-Dynamic */ = {
isa = XCSwiftPackageProductDependency;
package = E2800F872C4A70AB003D93A6 /* XCRemoteSwiftPackageReference "Swinject" */;
productName = "Swinject-Dynamic";
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 2A9D4523292C805D008FABEB /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "3d86c27e292d873d79d584e6fc741c291c76f2740cd77104411d0aa531cba1c0",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -35,7 +36,16 @@
"revision" : "467a3d17479887943ab917a379e62bbaff60ac8a",
"version" : "2.1.1"
}
},
{
"identity" : "swinject",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Swinject/Swinject",
"state" : {
"revision" : "be9dbcc7b86811bc131539a20c6f9c2d3e56919f",
"version" : "2.9.1"
}
}
],
"version" : 2
"version" : 3
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>GettingStarted (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>GettingStarted (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>GettingStarted (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Sample-iOS (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>5</integer>
</dict>
<key>Sample-iOS (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>6</integer>
</dict>
<key>Sample-iOS (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>TheMealsApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion TheMealsApp/TheMealsApp/App/TheMealsAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

@main
struct TheMealsAppApp: App {
let homePresenter = HomePresenter(homeUseCase: Injection.init().provideHome())
let homePresenter = HomePresenter(homeUseCase: Injection.shared.provideHome())

var body: some Scene {
WindowGroup {
Expand Down
47 changes: 37 additions & 10 deletions TheMealsApp/TheMealsApp/Core/DI/Injection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,53 @@

import Foundation
import RealmSwift
import Swinject

final class Injection: NSObject {
final class Injection {

static let shared = Injection()

private func provideRepository() -> MealRepositoryProtocol {
let realm = try? Realm()
let container: Container

let locale: LocaleDataSource = LocaleDataSource.sharedInstance(realm)
let remote: RemoteDataSource = RemoteDataSource.sharedInstance
private init() {
container = Container()

return MealRepository.sharedInstance(locale, remote)
container.register(Realm.self) { _ in
try! Realm()
}

container.register(LocaleDataSource.self) { resolver in
let realm = resolver.resolve(Realm.self)
return LocaleDataSource.sharedInstance(realm)
}

container.register(RemoteDataSource.self) { resolver in
return RemoteDataSource.sharedInstance
}

container.register(MealRepositoryProtocol.self) { resolver in
let locale = resolver.resolve(LocaleDataSource.self)!
let remote = resolver.resolve(RemoteDataSource.self)!
return MealRepository.sharedInstance(locale, remote)
}

container.register(HomeUseCase.self) { resolver in
let repository = resolver.resolve(MealRepositoryProtocol.self)!
return HomeInteractor(repository: repository)
}

container.register(DetailUseCase.self) { (resolver, category: CategoryModel) in
let repository = resolver.resolve(MealRepositoryProtocol.self)!
return DetailInteractor(repository: repository, category: category)
}
}

func provideHome() -> HomeUseCase {
let repository = provideRepository()
return HomeInteractor(repository: repository)
return container.resolve(HomeUseCase.self)!
}

func provideDetail(category: CategoryModel) -> DetailUseCase {
let repository = provideRepository()
return DetailInteractor(repository: repository, category: category)
return container.resolve(DetailUseCase.self, argument: category)!
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
class HomeRouter {

func makeDetailView(for category: CategoryModel) -> some View {
let detailUseCase = Injection.init().provideDetail(category: category)
let detailUseCase = Injection.shared.provideDetail(category: category)
let presenter = DetailPresenter(detailUseCase: detailUseCase)
return DetailView(presenter: presenter)
}
Expand Down