diff --git a/Sources/ServiceLocator/ResolutionError.swift b/Sources/ServiceLocator/ResolutionError.swift index b8c51ad..6169617 100644 --- a/Sources/ServiceLocator/ResolutionError.swift +++ b/Sources/ServiceLocator/ResolutionError.swift @@ -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 { diff --git a/Sources/ServiceLocator/ServiceLocator.swift b/Sources/ServiceLocator/ServiceLocator.swift index 3252c84..cb7c4b9 100644 --- a/Sources/ServiceLocator/ServiceLocator.swift +++ b/Sources/ServiceLocator/ServiceLocator.swift @@ -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 @@ -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. @@ -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.