@@ -7,61 +7,6 @@ protocol InstanceWrapper {
77 init ? ( inContainer container: Container , 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 : Container ?
19-
20- init ? ( inContainer container: Container , 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 _: Container , 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-
6510extension Optional : InstanceWrapper {
6611 static var wrappedType : Any . Type { return Wrapped . self }
6712
0 commit comments