From e829b8141b093e5a5b5b1202eb9b3f5e5c80f3e1 Mon Sep 17 00:00:00 2001 From: Brendan Szymanski Date: Wed, 10 Jun 2026 17:04:11 -0400 Subject: [PATCH] Add DIContainer singleton with key path registration --- Sources/LuminateCore/DIContainer.swift | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sources/LuminateCore/DIContainer.swift 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() + } + +}