diff --git a/Sources/LuminateCore/DIContainer.swift b/Sources/LuminateCore/DIContainer.swift new file mode 100644 index 0000000..4ff1435 --- /dev/null +++ b/Sources/LuminateCore/DIContainer.swift @@ -0,0 +1,34 @@ +import Foundation + +@MainActor +public final class DIContainer { + + public static let shared = DIContainer() + public private(set) var values = InjectionValues() + + private init() {} + + public func register( + _ keyPath: WritableKeyPath, + value: T + ) { + values[keyPath: keyPath] = value + } + + public func resolve( + _ keyPath: KeyPath + ) -> T { + guard let value = values[keyPath: keyPath] else { + fatalError( + "DIContainer: No value registered for \(keyPath). " + + "Call DIContainer.shared.register(\\.key, value:) during app startup." + ) + } + return value + } + + public func reset() { + values = InjectionValues() + } + +}