Skip to content

Instantly share code, notes, and snippets.

@SemyonovE
Last active February 28, 2023 01:51
Show Gist options
  • Select an option

  • Save SemyonovE/1047bb5d08aa7da36e5b07cc8f714568 to your computer and use it in GitHub Desktop.

Select an option

Save SemyonovE/1047bb5d08aa7da36e5b07cc8f714568 to your computer and use it in GitHub Desktop.
class HardService: ServiceImplementationProtocol {
static var kind: ServiceContainerKind { .temporary }
unowned let serviceLocator: ServiceLocator
private let someString: String
private let someService: ServiceImplementationProtocol
required init(serviceLocator: ServiceLocator) { fatalError() }
init(
serviceLocator: ServiceLocator,
string: String,
service: ServiceImplementationProtocol
) {
self.serviceLocator = serviceLocator
self.someString = string
self.someService = service
}
}
extension HardService {
static let defaultCreator: (ServiceLocator) -> (HardService) = {
let service3: Service3 = $0.resolve()
return HardService(
serviceLocator: $0,
string: "Some service string",
service: service3
)
}
}
// Using
let hardService: HardService = serviceLocator.resolve(creator: HardService.defaultCreator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment