Skip to content

Commit 0904ef9

Browse files
committed
Remove Lazy and Provider wrapper types
1 parent 38a23ff commit 0904ef9

7 files changed

Lines changed: 0 additions & 672 deletions

File tree

Sources/Swinject/InstanceWrapper.swift

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,6 @@ protocol InstanceWrapper {
77
init?(inContainer container: SwinjectContainer, withInstanceFactory factory: ((GraphIdentifier?) -> Any?)?)
88
}
99

10-
/// Wrapper to enable delayed dependency instantiation.
11-
/// `Lazy<Type>` does not need to be explicitly registered into the ``Container`` - resolution will work
12-
/// as long as there is a registration for the `Type`.
13-
public final class Lazy<Service>: InstanceWrapper {
14-
static var wrappedType: Any.Type { return Service.self }
15-
16-
private let factory: (GraphIdentifier?) -> Any?
17-
private let graphIdentifier: GraphIdentifier?
18-
private weak var container: SwinjectContainer?
19-
20-
init?(inContainer container: SwinjectContainer, withInstanceFactory factory: ((GraphIdentifier?) -> Any?)?) {
21-
guard let factory = factory else { return nil }
22-
self.factory = factory
23-
graphIdentifier = container.currentObjectGraph
24-
self.container = container
25-
}
26-
27-
private var _instance: Service?
28-
29-
/// Getter for the wrapped object.
30-
/// It will be resolved from the ``Container`` when first accessed, all other calls will return the same instance.
31-
public var instance: Service {
32-
if let instance = _instance {
33-
return instance
34-
} else {
35-
_instance = makeInstance()
36-
return _instance!
37-
}
38-
}
39-
40-
private func makeInstance() -> Service? {
41-
factory(graphIdentifier) as? Service
42-
}
43-
}
44-
45-
/// Wrapper to enable delayed dependency instantiation.
46-
/// `Provider<Type>` does not need to be explicitly registered into the ``Container`` - resolution will work
47-
/// as long as there is a registration for the `Type`.
48-
public final class Provider<Service>: InstanceWrapper {
49-
static var wrappedType: Any.Type { return Service.self }
50-
51-
private let factory: (GraphIdentifier?) -> Any?
52-
53-
init?(inContainer _: SwinjectContainer, withInstanceFactory factory: ((GraphIdentifier?) -> Any?)?) {
54-
guard let factory = factory else { return nil }
55-
self.factory = factory
56-
}
57-
58-
/// Getter for the wrapped object.
59-
/// New instance will be resolved from the ``Container`` every time it is accessed.
60-
public var instance: Service {
61-
return factory(.none) as! Service
62-
}
63-
}
64-
6510
extension Optional: InstanceWrapper {
6611
static var wrappedType: Any.Type { return Wrapped.self }
6712

Tests/SwinjectTests/Circularity.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,3 @@ internal class DDependingOnBC: D {
7070
internal class CDependingOnWeakB: C {
7171
weak var b: B?
7272
}
73-
74-
internal protocol LazyParentProtocol {
75-
var child1: LazyChildProtocol { get }
76-
var child2: LazyChildProtocol { get }
77-
}
78-
internal protocol LazyChildProtocol: AnyObject {
79-
var lazy: Lazy<LazilyResolvedProtocol> { get }
80-
}
81-
internal protocol LazySingletonProtocol {
82-
var lazy: Lazy<LazilyResolvedProtocol> { get }
83-
}
84-
internal protocol LazilyResolvedProtocol: AnyObject { }
85-
86-
internal class LazyParent: LazyParentProtocol {
87-
let child1: LazyChildProtocol
88-
let child2: LazyChildProtocol
89-
90-
init(child1: LazyChildProtocol, child2: LazyChildProtocol) {
91-
self.child1 = child1
92-
self.child2 = child2
93-
}
94-
}
95-
96-
internal class LazyChild: LazyChildProtocol, LazySingletonProtocol {
97-
let lazy: Lazy<LazilyResolvedProtocol>
98-
99-
init(lazy: Lazy<LazilyResolvedProtocol>) {
100-
self.lazy = lazy
101-
}
102-
}
103-
104-
internal class LazilyResolved: LazilyResolvedProtocol { }

Tests/SwinjectTests/ContainerTests.Speed.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ fileprivate extension SwinjectContainer {
4545
for _ in 0..<500_000 {
4646
_ = resolve(Animal.self) as? Cat
4747
_ = resolve(Animal.self, argument: "Mimi") as? Cat
48-
let lazy = resolve(Lazy<Animal>.self, arguments: "Mew", true)
49-
_ = lazy?.instance as? Cat
5048
}
5149
}
5250
}

Tests/SwinjectTests/EmploymentAssembly.swift

Lines changed: 0 additions & 80 deletions
This file was deleted.

Tests/SwinjectTests/LazyTests.swift

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)