Created
August 8, 2024 16:23
-
-
Save achernoprudov/96da0ea50f8f6f9ac8eaf23063867d34 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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