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
func resolve<Service: Configurable>(type: Service.Type, configuration: Service.Configuration) -> Service? { | |
let service = resolve(type: type) // 1 | |
service?.configure(configuration: configuration) // 2 | |
return service | |
} |
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
dic.register(type: ServiceThreeConfigurable.self) { (dic) -> AnyObject in // 1 | |
return ServiceThreeConfigurable(serviceOne: dic.resolve(type: ServiceOneProtocol.self)!) | |
} | |
let configuration = ServiceThreeConfigurable.ServiceThreeConfiguration(paramOne: true, paramTwo: Data()) // 2 | |
let serviceThree = dic.resolve(type: ServiceThreeConfigurable.self, configuration: configuration) // 3 |
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
class ServiceThreeConfigurable: ServiceThreeProtocol, Configurable { // 1 | |
struct ServiceThreeConfiguration { // 2 | |
var paramOne: Bool | |
var paramTwo: Data | |
} | |
let serviceOne: ServiceOneProtocol | |
var paramOne: Bool! // 3 | |
var paramTwo: Data! |
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
protocol Configurable { | |
associatedtype Configuration | |
func configure(configuration: Configuration) | |
} |
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
protocol DICProtocol { | |
func register<Service>(type: Service.Type, factoryClosure: @escaping FactoryClosure) | |
func resolve<Service>(type: Service.Type) -> Service? | |
func resolve<Service: Configurable>(type: Service.Type, configuration: Service.Configuration) -> Service? | |
} |
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
protocol DICProtocol { | |
func register<Service>(type: Service.Type, factoryClosure: @escaping FactoryClosure) | |
func resolve<Service>(type: Service.Type) -> Service? | |
} |
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
dic.register(type: ServiceThreeProtocol.self) { (dic) -> AnyObject in | |
return ServiceThree(serviceOne: dic.resolve(type: ServiceOneProtocol.self)!, | |
paramOne: true, | |
paramTwo: Data()) | |
} |
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
class ServiceThree: ServiceThreeProtocol { | |
let serviceOne: ServiceOneProtocol | |
let paramOne: Bool | |
let paramTwo: Data | |
init(serviceOne: ServiceOneProtocol, paramOne: Bool, paramTwo: Data) { | |
self.serviceOne = serviceOne | |
self.paramOne = paramOne | |
self.paramTwo = paramTwo |