Skip to content

Dependency

apleshkov edited this page Jul 26, 2018 · 1 revision

Dependency

App

// @saber.container(AppContainer)
// @saber.scope(App)
protocol AppContaining {}

// @saber.scope(App)
class NetworkManager {
}

User

// @saber.container(UserContainer)
// @saber.scope(User)
// @saber.dependsOn(AppContainer)
protocol UserContaining {}

// @saber.scope(User)
class UserAPI {
    
    init(networkManager: NetworkManager) {
        // ...
    }
}

Generated:

internal class UserContainer: UserContaining {

    internal unowned let appContainer: AppContainer

    internal init(appContainer: AppContainer) {
        self.appContainer = appContainer
    }

    internal var userAPI: UserAPI {
        let userAPI = self.makeUserAPI()
        return userAPI
    }

    private func makeUserAPI() -> UserAPI {
        return UserAPI(networkManager: self.appContainer.networkManager)
    }

}
Clone this wiki locally