Skip to content

Commit

Permalink
LazyForwardingInstantiator -> ForwardingInstantiator. LazyInstantiato…
Browse files Browse the repository at this point in the history
…r -> Instantiator
  • Loading branch information
dfed committed Dec 5, 2023
1 parent 1428425 commit e1336e6
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

/// A SafeDI dependency designed for the lazy instantiation of an `@Instantiable` type that contains
/// A SafeDI dependency designed for the deferred instantiation of an `@Instantiable` type that contains
/// `@Forwarded` properties. This class enables instantiation with specific arguments, facilitating
/// the inheritance of these arguments by `@Instantiable` types that are `@Instantiated` within
/// the `InstantiableType`, as well as by all types `@Instantiated` downstream.
/// Instantiation is thread-safe.
///
/// - SeeAlso: `LazyInstantiator`
/// - SeeAlso: `Instantiator`
/// - Note: This class is the sole means for instantiating an `@Instantiable` type with `@Forwarded`
/// properties within the SafeDI framework.
public final class LazyForwardingInstantiator<ArgumentsToForward, InstantiableType> {
/// Initializes a new lazy forwarding instantiator with the provided instantiation closure.
public final class ForwardingInstantiator<ArgumentsToForward, InstantiableType> {
/// Initializes a new forwarding instantiator with the provided instantiation closure.
///
/// - Parameter instantiator: A closure that takes `ArgumentsToForward` and returns an instance of `InstantiableType`.
public init(_ instantiator: @escaping (ArgumentsToForward) -> InstantiableType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

/// A SafeDI dependency responsible for the lazy instantiation of an `@Instantiable` type.
/// A SafeDI dependency responsible for the deferred instantiation of an `@Instantiable` type.
/// This class facilitates the delayed creation of an `@Instantiable` instance, making it particularly
/// useful in scenarios where immediate instantiation is not necessary or desirable. `LazyInstantiator`
/// useful in scenarios where immediate instantiation is not necessary or desirable. `Instantiator`
/// facilitates control over memory usage and enables just-in-time instantiation. Instantiation is thread-safe.
///
/// - SeeAlso: `LazyForwardingInstantiator`
public final class LazyInstantiator<InstantiableType> {
/// - SeeAlso: `ForwardingInstantiator`
public final class Instantiator<InstantiableType> {
/// - Parameter instantiator: A closure that returns an instance of `InstantiableType`.
public init(_ instantiator: @escaping () -> InstantiableType) {
self.instantiator = instantiator
Expand Down
8 changes: 4 additions & 4 deletions Sources/SafeDI/LazyInstantiated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import Foundation

// MARK: Initialization

public init(synchronization: SynchronizationBehavior = .main, _ builder: LazyInstantiator<InstantiableType>) {
self.lazyInstantiator = builder
public init(synchronization: SynchronizationBehavior = .main, _ builder: Instantiator<InstantiableType>) {
self.instantiator = builder
self.synchronization = synchronization
}

Expand All @@ -37,7 +37,7 @@ import Foundation
if let instantiated = self._unsafeInstantiated {
return instantiated
} else {
let instantiated = self.lazyInstantiator.instantiate()
let instantiated = self.instantiator.instantiate()
self._unsafeInstantiated = instantiated
return instantiated
}
Expand All @@ -46,7 +46,7 @@ import Foundation

// MARK: Private

private let lazyInstantiator: LazyInstantiator<InstantiableType>
private let instantiator: Instantiator<InstantiableType>
private let synchronization: SynchronizationBehavior
private var _unsafeInstantiated: InstantiableType?

Expand Down
8 changes: 4 additions & 4 deletions Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ extension Property {
fileprivate var nonLazyPropertyType: Scope.PropertyToInstantiate.PropertyType {
switch typeDescription {
case let .simple(name, _):
if name == Dependency.lazyInstantiatorType {
if name == Dependency.instantiatorType {
return .instantiator
} else if name == Dependency.lazyForwardingInstantiatorType {
} else if name == Dependency.forwardingInstantiatorType {
return .forwardingInstantiator
} else {
return .constant
Expand Down Expand Up @@ -368,11 +368,11 @@ extension TypeDescription {
fileprivate var asInstantiatedType: TypeDescription {
switch self {
case let .simple(name, generics):
if name == Dependency.lazyInstantiatorType, let builtType = generics.first {
if name == Dependency.instantiatorType, let builtType = generics.first {
// This is a type that is lazily instantiated.
// The first generic is the built type.
return builtType
} else if name == Dependency.lazyForwardingInstantiatorType, let builtType = generics.last {
} else if name == Dependency.forwardingInstantiatorType, let builtType = generics.last {
// This is a type that is lazily instantiated with forwarded arguments.
// The last generic is the built type.
return builtType
Expand Down
8 changes: 4 additions & 4 deletions Sources/SafeDICore/Models/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public struct Dependency: Codable, Hashable {
case .instantiated, .inherited, .singleton, .forwarded:
return property.label
case .lazyInstantiated:
return "\(property.label)\(Self.lazyInstantiatorType)"
return "\(property.label)\(Self.instantiatorType)"
}
}

Expand All @@ -77,12 +77,12 @@ public struct Dependency: Codable, Hashable {
case .lazyInstantiated:
// TODO: fully qualify this type with `SafeDI.` member prefix
return .simple(
name: Self.lazyInstantiatorType,
name: Self.instantiatorType,
generics: [property.typeDescription]
)
}
}

static let lazyInstantiatorType = "LazyInstantiator"
static let lazyForwardingInstantiatorType = "LazyForwardingInstantiator"
static let instantiatorType = "Instantiator"
static let forwardingInstantiatorType = "ForwardingInstantiator"
}
32 changes: 16 additions & 16 deletions Tests/SafeDICoreTests/InitializerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ final class InitializerTests: XCTestCase {
hasGenericWhereClause: false,
arguments: [
.init(
innerLabel: "invariantLazyInstantiator",
innerLabel: "invariantInstantiator",
typeDescription: .simple(
name: "LazyInstantiator",
name: "Instantiator",
generics: [.simple(name: "Invariant")]
)
),
Expand All @@ -769,9 +769,9 @@ final class InitializerTests: XCTestCase {
fulfilling: [
.init(
property: .init(
label: "invariantLazyInstantiator",
label: "invariantInstantiator",
typeDescription: .simple(
name: "LazyInstantiator",
name: "Instantiator",
generics: [.simple(name: "Invariant")]
)
),
Expand All @@ -781,9 +781,9 @@ final class InitializerTests: XCTestCase {
typeIsClass: false,
trailingNewline: true).description,
"""
public init(buildSafeDIDependencies: () -> (LazyInstantiator<Invariant>)) {
public init(buildSafeDIDependencies: () -> (Instantiator<Invariant>)) {
let dependencies = buildSafeDIDependencies()
self.init(invariantLazyInstantiator: dependencies)
self.init(invariantInstantiator: dependencies)
}
"""
)
Expand All @@ -798,9 +798,9 @@ final class InitializerTests: XCTestCase {
hasGenericWhereClause: false,
arguments: [
.init(
innerLabel: "invariantLazyInstantiator",
innerLabel: "invariantInstantiator",
typeDescription: .simple(
name: "LazyInstantiator",
name: "Instantiator",
generics: [.simple(name: "Invariant")]
)
),
Expand All @@ -821,9 +821,9 @@ final class InitializerTests: XCTestCase {
typeIsClass: false,
trailingNewline: true).description,
"""
public init(buildSafeDIDependencies: () -> (LazyInstantiator<Invariant>)) {
public init(buildSafeDIDependencies: () -> (Instantiator<Invariant>)) {
let dependencies = buildSafeDIDependencies()
self.init(invariantLazyInstantiator: dependencies)
self.init(invariantInstantiator: dependencies)
}
"""
)
Expand All @@ -838,9 +838,9 @@ final class InitializerTests: XCTestCase {
hasGenericWhereClause: false,
arguments: [
.init(
innerLabel: "invariantLazyInstantiator",
innerLabel: "invariantInstantiator",
typeDescription: .simple(
name: "LazyInstantiator",
name: "Instantiator",
generics: [.simple(name: "Invariant")]
)
),
Expand All @@ -852,9 +852,9 @@ final class InitializerTests: XCTestCase {
fulfilling: [
.init(
property: .init(
label: "invariantLazyInstantiator",
label: "invariantInstantiator",
typeDescription: .simple(
name: "LazyInstantiator",
name: "Instantiator",
generics: [.simple(name: "Invariant")]
)
),
Expand All @@ -871,9 +871,9 @@ final class InitializerTests: XCTestCase {
typeIsClass: false,
trailingNewline: true).description,
"""
public init(buildSafeDIDependencies: () -> (LazyInstantiator<Invariant>)) {
public init(buildSafeDIDependencies: () -> (Instantiator<Invariant>)) {
let dependencies = buildSafeDIDependencies()
self.init(invariantLazyInstantiator: dependencies)
self.init(invariantInstantiator: dependencies)
}
"""
)
Expand Down
Loading

0 comments on commit e1336e6

Please sign in to comment.