You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/SessionUtilitiesKit/Dependency Injection/SingletonInfo.swift

34 lines
778 B
Swift

// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import Foundation
// MARK: - Singleton
public class Singleton {}
// MARK: - SingletonInfo
public enum SingletonInfo {
public class Config<S>: Singleton {
public let key: Int
public let createInstance: (Dependencies) -> S
fileprivate init(
createInstance: @escaping (Dependencies) -> S
) {
self.key = ObjectIdentifier(S.self).hashValue
self.createInstance = createInstance
}
}
}
public extension SingletonInfo {
static func create<S>(
createInstance: @escaping (Dependencies) -> S
) -> SingletonInfo.Config<S> {
return SingletonInfo.Config(
createInstance: createInstance
)
}
}