Skip to content

Commit

Permalink
removed eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
kibotu committed Jul 17, 2024
1 parent 6c4abc1 commit c4a3e90
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/ServiceLocator/ResolutionError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Error thrown when a dependency cannot be resolved
struct ResolutionError : LocalizedError, CustomStringConvertible {
struct ResolutionError: LocalizedError, CustomStringConvertible {
let message: String

public var description: String {
Expand Down
10 changes: 1 addition & 9 deletions Sources/ServiceLocator/ServiceLocator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import Foundation
public class ServiceLocator {
static var enableLogging: Bool = false

/// Determines if singletons should be created eagerly or lazily
private let eagerly: Bool = true

/// Stores factories for eagerly created singletons
private var singletonFactories: [DependencyWithKey] = []
/// Stores already created singleton instances
Expand Down Expand Up @@ -48,11 +45,7 @@ public class ServiceLocator {
guard singletons[key] == nil else {
fatalError("[single] Factory for \(key) already exists.")
}
if eagerly {
singletonFactories.append(DependencyWithKey(key: key, factory: factory))
} else {
singletons[key] = factory()
}
singletonFactories.append(DependencyWithKey(key: key, factory: factory))
}

/// Resolves and returns an instance of the specified type.
Expand Down Expand Up @@ -122,7 +115,6 @@ public class ServiceLocator {
}
}


/// Initializes and configures a new `ServiceLocator` optionally with provided modules configuration closures.
/// - Parameter closure: An optional closure returning one or more configured modules.
/// - Returns: A fully initialized `ServiceLocator` object ready to use in your application.
Expand Down

0 comments on commit c4a3e90

Please sign in to comment.