Skip to content

Commit 8b28dca

Browse files
Added comment documentation
1 parent 00e5f5e commit 8b28dca

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CodeEdit/Utils/DependencyInjection/ServiceContainer.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,31 @@
77

88
import Foundation
99

10+
/// A service container that manages the registration and resolution of services.
1011
enum ServiceContainer {
12+
/// A dictionary storing the closures for creating service instances.
1113
private static var factories: [ObjectIdentifier: () -> Any] = [:]
14+
/// A dictionary storing the cached service instances.
1215
private static var cache: [ObjectIdentifier: Any] = [:]
16+
/// A dispatch queue used for synchronizing access to the factories and cache.
1317
private static let queue = DispatchQueue(label: "ServiceContainerQueue")
1418

19+
/// Registers a factory closure for creating instances of a service type.
20+
///
21+
/// - Parameter factory: An autoclosure that returns an instance of the service type.
1522
static func register<Service>(_ factory: @autoclosure @escaping () -> Service) {
1623
queue.sync {
1724
let key = ObjectIdentifier(Service.Type.self)
1825
factories[key] = factory
1926
}
2027
}
2128

29+
/// Resolves an instance of a service type based on the specified resolution type.
30+
///
31+
/// - Parameters:
32+
/// - resolveType: The type of resolution to use for the service. Defaults to `.singleton`.
33+
/// - type: The type of the service to resolve.
34+
/// - Returns: An instance of the resolved service type, or `nil` if the service is not registered.
2235
static func resolve<Service>(_ resolveType: ServiceType = .singleton, _ type: Service.Type) -> Service? {
2336
let serviceId = ObjectIdentifier(Service.Type.self)
2437

CodeEdit/Utils/DependencyInjection/ServiceWrapper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Abe Malla on 4/3/24.
66
//
77

8+
/// A property wrapper that provides access to a service instance.
89
@propertyWrapper
910
struct Service<Service> {
1011
var service: Service

0 commit comments

Comments
 (0)