35 lines
781 B
Swift
35 lines
781 B
Swift
//
|
|
// Injected.swift
|
|
// LuminateDI
|
|
//
|
|
// Created by Brendan Szymanski on 6/14/26.
|
|
//
|
|
|
|
import Adwaita
|
|
import Foundation
|
|
|
|
@propertyWrapper
|
|
public struct Injected<T> {
|
|
|
|
private let keyPath: KeyPath<InjectionValues, T?>
|
|
private let observerRef: ObserverRef
|
|
|
|
public var wrappedValue: T {
|
|
DIContainer.shared.resolve(keyPath)
|
|
}
|
|
|
|
public init(_ keyPath: KeyPath<InjectionValues, T?>) {
|
|
self.keyPath = keyPath
|
|
self.observerRef = ObserverRef(
|
|
id: DIContainer.shared.addObserver(for: keyPath) {
|
|
StateManager.updateViews()
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
private final class ObserverRef: @unchecked Sendable {
|
|
let id: UUID
|
|
init(id: UUID) { self.id = id }
|
|
deinit { DIContainer.shared.removeObserver(id) }
|
|
}
|