Skip to content
apleshkov edited this page Jul 30, 2018 · 4 revisions

Use the @saber.bindTo(Protocol) to keep a dependency abstract.

protocol Logging {
    
    func log(_ message: String)
}

// @saber.scope(App)
// @saber.bindTo(Logging)
class ConsoleLogger: Logging {
    
    func log(_ message: String) {
        print(message)
    }
}

// @saber.scope(App)
class NetworkManager {
    
    // @saber.inject
    init(logger: Logging) {
        // ...
    }
}

Unfortunately it's impossible to declare another logger implementation and also bind it to the Logging protocol. Use providers for additional cases.

Clone this wiki locally