Skip to content

Commit ab1e2da

Browse files
authored
[WIP] Revamping Library Interface and Resolving Design Mistakes. (v1.1.0) (#8)
1 parent 2228c86 commit ab1e2da

23 files changed

+671
-1266
lines changed

.swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>FILEHEADER</key>
6-
<string>
7-
//===----------------------------------------------------------------------===//
6+
<string>===----------------------------------------------------------------------===//
87
//
98
// This source file is part of the Inject package open source project
109
//
@@ -16,7 +15,6 @@
1615
//
1716
// SPDX-License-Identifier: MIT
1817
//
19-
//===----------------------------------------------------------------------===//
20-
//</string>
18+
//===----------------------------------------------------------------------===//</string>
2119
</dict>
2220
</plist>
File renamed without changes.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let package = Package(
3333
name: "Inject", dependencies: [], path: "Sources"
3434
),
3535
.testTarget(
36-
name: "Inject-Tests", dependencies: ["Inject"], path: "Tests"
37-
)
36+
name: "Tests", dependencies: ["Inject"], path: "Tests"
37+
),
3838
]
3939
)

Sources/DefaultValues.swift renamed to Sources/Deprecating/DefaultValues.swift

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,8 @@
1414

1515
import Foundation
1616

17-
/// Provides an interface to extend with computed properties.
18-
/// Each computed property provides a name to reference in ``Injected``
19-
/// and a type for enclosed ``Dependency``.
20-
/// ```swift
21-
/// extension DefaultValues {
22-
/// var testService: TestServiceInterface { TestService() }
23-
/// }
24-
/// ```
25-
///> Warning:
26-
/// **Never use the @Injected inside another @Injected**
27-
/// it will create a cycle and your application will hang and
28-
/// then possibly killed by the system.
29-
/// ```swift
30-
/// var auth: Auth {
31-
/// @Injected(\.network) var network // DON'T
32-
/// Auth(network: network.instance)
33-
/// }
34-
///
35-
/// var network: Networking {
36-
/// @Injected(\.auth) var auth // DON'T
37-
/// Networking(auth: auth.instance)
38-
/// }
39-
/// ```
40-
/// Instead, move the dependency from the initializer into the injected property.
41-
/// ```swift
42-
/// final class Networking {
43-
/// @Injected(\.auth) var auth
44-
/// }
45-
///
46-
/// final class Auth {
47-
/// @Injected(\.network) var network
48-
/// }
49-
/// ```
50-
/// now you can remove them from initializer and can safely resolve this cross dependency.
51-
/// ```swift
52-
/// extension DefaultValues {
53-
/// var auth: Auth { Auth() }
54-
/// var network: Networking { Networking() }
55-
/// }
56-
/// ```
57-
@MainActor
58-
public final class DefaultValues {
17+
@available(*, deprecated, message: "Inject doesn't use DefaultValues any more, please refer to Readme.")
18+
@MainActor public final class DefaultValues {
5919
public typealias KeyPath<Value> = Swift.KeyPath<DefaultValues, Value>
6020

6121
private static let shared = DefaultValues()

Sources/Dependency.swift renamed to Sources/Deprecating/Dependency.swift

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Foundation
1616

1717
// MARK: - Public interface
18+
@available(*, deprecated, message: "Inject doesn't use Dependency<Value> any more, please refer to Readme.")
1819
extension Dependency {
1920
/// An instance of the dependency.
2021
public var instance: Value {
@@ -28,65 +29,8 @@ extension Dependency {
2829
}
2930
}
3031

31-
// MARK: - Dependency<Value>
32-
/// A type that represents a dependency with given ``Scope`` and ``Lifespan``.
33-
///
34-
/// When you use
35-
/// ```swift
36-
/// final class MyAwesomeComponent: Injectable {
37-
/// @Injected(\.someServiceKey, .temporary, .local) var service
38-
/// }
39-
/// ```
40-
/// `service` variable is of type ``Dependency``.
41-
/// The instance itself, using ``Dependency/instance``
42-
/// is of type `someServiceKey` in ``DefaultValues`` is e.g.
43-
/// `SomeServiceInterface` protocol.
44-
///
45-
/// ``Injectable`` marks the class to tell the compiler
46-
/// it has ``Injectable/injecting(_:for:)`` function.
47-
///
48-
/// ## Scope and Lifespan configuration
49-
///
50-
/// **`.temporary`** is the configuration of the ``Lifespan`` meaning
51-
/// we don't want to hold the instance of this service once we are done.
52-
///
53-
/// **`.local`** is the ``Scope`` of the injection,
54-
/// which means we want our personal instance to be provided,
55-
/// not the one that is shared with others.
56-
///
57-
/// _You can omit both `.temporary` and `.local` since these are_
58-
/// _the default values for the configuration._
59-
/// ```swift
60-
/// final class MyAwesomeComponent: Injectable {
61-
/// @Injected(\.someServiceKey) var service
62-
/// }
63-
/// ```
64-
///
65-
/// Now you can access your instance using the ``Dependency/instance`` computed property.
66-
/// ```swift
67-
/// func do() {
68-
/// service.instance.doWork()
69-
/// }
70-
/// ```
71-
///
72-
/// ## Injecting
73-
/// To inject another than production instance in your tests or previews
74-
/// or anywhere else:
75-
/// ```swift
76-
/// let component = MyAwesomeComponent()
77-
/// .injecting(
78-
/// SomeMock(), // injected instance
79-
/// for: \.service
80-
/// )
81-
/// // component.service.instance is the injected instance that we provided.
82-
/// ```
83-
///
84-
/// Note that we use the `KeyPath` to the variable in `MyAwesomeComponent` and
85-
/// not in the ``DefaultValues`` that's because we want to inject only
86-
/// for `MyAwesomeComponent` without affecting other consumers of the service.
87-
///
88-
@MainActor
89-
public final class Dependency<Value> {
32+
@available(*, deprecated, message: "Inject doesn't use Dependency<Value> any more, please refer to Readme.")
33+
@MainActor public final class Dependency<Value> {
9034
typealias StorageKeyPath = DefaultValues.KeyPath<Value>
9135

9236
private let storageKeyPath: StorageKeyPath
File renamed without changes.

Sources/Injectable.swift renamed to Sources/Deprecating/Injectable.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
//===----------------------------------------------------------------------===//
1414
import Foundation
1515

16-
/// Adds ``injecting(_:for:)`` to enable ``Dependency`` overriding.
16+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
1717
public protocol Injectable {}
1818

19+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
1920
public extension Injectable {
20-
21-
/// Replaces the instance of the `Value` for given ``Injected`` property.
22-
///
23-
/// - Parameters:
24-
/// - newValue: A value to replace with.
25-
/// - keyPath: Key path to the ``Injected`` property.
26-
/// - Returns: An instance of the dependency of type `Value`
21+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
2722
@MainActor func injecting<Value>(
2823
_ newValue: Value,
2924
for keyPath: KeyPath<Self, Dependency<Value>>

Sources/Injected-PropertyWrapper.swift renamed to Sources/Deprecating/Injected-PropertyWrapper.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,7 @@
1414

1515
import Foundation
1616

17-
/// An injected property that provides an ``Dependency/instance``
18-
/// based on configuration.
19-
///
20-
/// To define an injection point anywhere in your app:
21-
/// ```swift
22-
/// final class MyAwesomeView: Injectable {
23-
/// @Injected(\.testService) var service
24-
/// }
25-
/// ```
26-
/// Then you can access the `testService` instance in your code
27-
/// by using ``Dependency/instance`` computed property.
28-
/// ```swift
29-
/// service.instance.doSomething()
30-
/// ```
31-
/// Depending on the ``Scope`` and ``Lifespan``
32-
/// provided it will be the new or shared instance.
17+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
3318
@MainActor
3419
@propertyWrapper
3520
public final

Sources/Lifespan.swift renamed to Sources/Deprecating/Lifespan.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
/// Dependency lifespan defines whether dependency
16-
/// needs to stay after consumer is deallocated.
15+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
1716
public enum Lifespan {
1817
/// Stays until application is alive.
1918
case permanent

Sources/Scope.swift renamed to Sources/Deprecating/Scope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
/// Defines the way an instance is obtained.
15+
@available(*, deprecated, message: "This api isn't available, please refer to Readme.")
1616
public enum Scope {
1717
/// New instance of a dependency.
1818
case local

0 commit comments

Comments
 (0)