Skip to content

Instantly share code, notes, and snippets.

@achernoprudov
Created August 8, 2024 16:23
Show Gist options
  • Save achernoprudov/96da0ea50f8f6f9ac8eaf23063867d34 to your computer and use it in GitHub Desktop.
Save achernoprudov/96da0ea50f8f6f9ac8eaf23063867d34 to your computer and use it in GitHub Desktop.
protocol BakendService {
func sum(first: Int, second: Int) -> Int
func someNumber() -> Int
}
class BakendServiceProxy: BakendService {
// lazy building function provided from DI
private let instanceBuilder: () -> BakendService
// instance which would be created when the first call
// to the service is made
private lazy var instance: BakendService = instanceBuilder()
init(instanceBuilder: @escaping () -> BakendService) {
self.instanceBuilder = instanceBuilder
}
func sum(first: Int, second: Int) -> Int {
instance.sum(first: first, second: second)
}
func someNumber() -> Int {
instance.someNumber()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment