diff --git a/SwiftInjection.podspec b/SwiftInjection.podspec index 6f88cf7..f11ce73 100644 --- a/SwiftInjection.podspec +++ b/SwiftInjection.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SwiftInjection' - s.version = '0.2' + s.version = '0.3' s.summary = 'A dependency injection framework for swift' s.homepage = 'https://github.com/aryaxt/SwiftInjection' s.license = { @@ -8,7 +8,7 @@ Pod::Spec.new do |s| :file => 'License.txt' } s.author = {'Aryan Ghassemi' => 'https://github.com/aryaxt/SwiftInjection'} - s.source = {:git => 'https://github.com/aryaxt/SwiftInjection.git', :tag => '0.2'} + s.source = {:git => 'https://github.com/aryaxt/SwiftInjection.git', :tag => '0.3'} s.platform = :ios, '8.0' s.source_files = 'SwiftInjection/*.{swift}' s.framework = 'Foundation' diff --git a/SwiftInjection/DIContainer.swift b/SwiftInjection/DIContainer.swift index beb30ec..8e6252b 100755 --- a/SwiftInjection/DIContainer.swift +++ b/SwiftInjection/DIContainer.swift @@ -26,7 +26,7 @@ public class DIContainer { - parameter module: A subclass of DIAbstractModule that implements DIModule */ public func addModule(module: T) { - module.load() + module.load(container: self) } /** diff --git a/SwiftInjection/DIModule.swift b/SwiftInjection/DIModule.swift index db1fcbc..01ae222 100644 --- a/SwiftInjection/DIModule.swift +++ b/SwiftInjection/DIModule.swift @@ -7,5 +7,5 @@ // public protocol DIModule { - func load() + func load(container container: DIContainer) } diff --git a/SwiftInjectionExample/SwiftInjectionExample/AppModule.swift b/SwiftInjectionExample/SwiftInjectionExample/AppModule.swift index c76e9fe..2ff1967 100644 --- a/SwiftInjectionExample/SwiftInjectionExample/AppModule.swift +++ b/SwiftInjectionExample/SwiftInjectionExample/AppModule.swift @@ -10,8 +10,9 @@ import SwiftInjection public class AppModule: DIAbstractModule, DIModule { - public func load() { - bind(GithubClient.self) { GithubHttpClient(baseUrl: "https://api.github.com") } + public func load(container container: DIContainer) { + bind(Client.self) { HttpClient(baseUrl: "https://api.github.com") } + bind(GithubClient.self) { GithubHttpClient(client: container.resolve(Client.self)) } bind(NSUserDefaults.self, asSingleton: false) { NSUserDefaults.standardUserDefaults() } bind(AnalyticsTracker.self, named: GoogleAnalyticsTracker.analyticsIdentifier()) { GoogleAnalyticsTracker() } bind(AnalyticsTracker.self, named: AmplitudeAnalyticsTracker.analyticsIdentifier()) { AmplitudeAnalyticsTracker() } diff --git a/SwiftInjectionExample/SwiftInjectionExample/NetworkLayer/Client.swift b/SwiftInjectionExample/SwiftInjectionExample/NetworkLayer/Client.swift index 26df117..fbb124c 100644 --- a/SwiftInjectionExample/SwiftInjectionExample/NetworkLayer/Client.swift +++ b/SwiftInjectionExample/SwiftInjectionExample/NetworkLayer/Client.swift @@ -22,7 +22,7 @@ public enum ClientError: ErrorType { case InvalidResponse } -protocol Client { +public protocol Client { func fetchObject(type type: T.Type, path: String, method: HttpMethod, completion: Result->Void) -> NSURLSessionDataTask func fetchObjects(type type: T.Type, path: String, method: HttpMethod, completion: Result<[T]>->Void) -> NSURLSessionDataTask } \ No newline at end of file diff --git a/SwiftInjectionExample/SwiftInjectionExample/Services/GithubHttpClient.swift b/SwiftInjectionExample/SwiftInjectionExample/Services/GithubHttpClient.swift index 22674ee..a2c0fd1 100644 --- a/SwiftInjectionExample/SwiftInjectionExample/Services/GithubHttpClient.swift +++ b/SwiftInjectionExample/SwiftInjectionExample/Services/GithubHttpClient.swift @@ -8,10 +8,16 @@ import Foundation -public class GithubHttpClient: HttpClient, GithubClient { +public class GithubHttpClient: GithubClient { + + private let client: Client + + public init(client: Client) { + self.client = client + } public func fetchRepos(user user: String, completion: Result<[Repository]>->Void) -> NSURLSessionTask { - return fetchObjects(type: Repository.self, path: "users/\(user)/repos", method: .Get, completion: completion) + return client.fetchObjects(type: Repository.self, path: "users/\(user)/repos", method: .Get, completion: completion) } } \ No newline at end of file