Skip to content

Commit

Permalink
Use specific providers for some IDs to demonstrate the resolve(tag) u…
Browse files Browse the repository at this point in the history
…sage

Also changed the XProviderAPIs to return a list of IDs instead of directly a list of object. This way we can use a provider to retrieve the IDs first and another to retrieve the Person from its ID which plays better with the demo
  • Loading branch information
AliSoftware committed Oct 10, 2015
1 parent 3bca744 commit 6085ce5
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 79 deletions.
4 changes: 4 additions & 0 deletions Example/Dip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
09D796031BC72691003C68EB /* StarshipCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D796021BC72691003C68EB /* StarshipCell.swift */; settings = {ASSET_TAGS = (); }; };
09D796071BC73E8B003C68EB /* StoryboardConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D796061BC73E8B003C68EB /* StoryboardConstants.swift */; settings = {ASSET_TAGS = (); }; };
09D7960D1BC7431C003C68EB /* FetchableTrait.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D7960C1BC7431C003C68EB /* FetchableTrait.swift */; settings = {ASSET_TAGS = (); }; };
09D796111BC97809003C68EB /* mainPilot.plist in Resources */ = {isa = PBXBuildFile; fileRef = 09D796101BC97809003C68EB /* mainPilot.plist */; settings = {ASSET_TAGS = (); }; };
607FACEC1AFB9204008FA782 /* SWAPIWebServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* SWAPIWebServiceTests.swift */; };
7BBD849465D99D9D1987AE6D /* Pods_DipTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 304AD039660A2C58EB08D985 /* Pods_DipTests.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
84D8EBE5B2D583BEFB17C45A /* Pods_DipSampleApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FE9C70E965FF88C3F20AC76 /* Pods_DipSampleApp.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
Expand Down Expand Up @@ -54,6 +55,7 @@
09D796021BC72691003C68EB /* StarshipCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarshipCell.swift; sourceTree = "<group>"; };
09D796061BC73E8B003C68EB /* StoryboardConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardConstants.swift; sourceTree = "<group>"; };
09D7960C1BC7431C003C68EB /* FetchableTrait.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchableTrait.swift; sourceTree = "<group>"; };
09D796101BC97809003C68EB /* mainPilot.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = mainPilot.plist; sourceTree = "<group>"; };
2FE9C70E965FF88C3F20AC76 /* Pods_DipSampleApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DipSampleApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
304AD039660A2C58EB08D985 /* Pods_DipTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DipTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
607FACE51AFB9204008FA782 /* DipTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DipTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -167,6 +169,7 @@
09D796061BC73E8B003C68EB /* StoryboardConstants.swift */,
0990226A1BC123C000E76F43 /* LaunchScreen.storyboard */,
0990226D1BC123C000E76F43 /* Info.plist */,
09D796101BC97809003C68EB /* mainPilot.plist */,
);
path = DipSampleApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -327,6 +330,7 @@
files = (
0900123B1BC6FF4D0079C600 /* Main.storyboard in Resources */,
0990226C1BC123C000E76F43 /* LaunchScreen.storyboard in Resources */,
09D796111BC97809003C68EB /* mainPilot.plist in Resources */,
099022691BC123C000E76F43 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
15 changes: 9 additions & 6 deletions Example/DipSampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
import UIKit
import Dip

let dip: DependencyContainer<String> = {
let dip = DependencyContainer<String>()
let dip: DependencyContainer<Int> = {
let dip = DependencyContainer<Int>()

// 1) Register the PersonProviderAPI singleton
// 1) Register the PersonProviderAPI singleton, one generic and one specific for a specific personID
dip.register(instance: DummyPilotProvider() as PersonProviderAPI)
let mainPersonProvider = PlistPersonProvider(plist: "mainPilot")
dip.register(0, instance: mainPersonProvider as PersonProviderAPI)

// 2) Register the StarshipProviderAPI, one generic and one specific for a specific pilot
dip.register() { DummyStarshipProvider(pilot: $0 ?? "Luke") as StarshipProviderAPI }
dip.register("Luke Skywalker") { HardCodedStarshipProvider() as StarshipProviderAPI }
// 2) Register the StarshipProviderAPI factories, one generic and one specific for a specific starshipID
dip.register() { HardCodedStarshipProvider() as StarshipProviderAPI }
let pilotName = mainPersonProvider.people[0].name
dip.register(0) { DummyStarshipProvider(pilotName: pilotName) as StarshipProviderAPI }

return dip
}()
Expand Down
Loading

0 comments on commit 6085ce5

Please sign in to comment.