Skip to content

Commit 609908e

Browse files
authored
Merge pull request #104 from StuClift/add-language-identifiers
Improve readability of code blocks in docs
2 parents 99ae25a + 653db1b commit 609908e

File tree

11 files changed

+50
-50
lines changed

11 files changed

+50
-50
lines changed

Documentation/Annotation.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is commonly done on Android using Dagger 2, and we can now do something sim
88

99
Resolver now supports resolving properties using the new property wrapper syntax in Swift 5.1.
1010

11-
```
11+
```swift
1212
class BasicInjectedViewController: UIViewController {
1313
@Injected var service: XYZService
1414
}
@@ -24,7 +24,7 @@ The Injected property wrapper will automatically instantiate objects using the c
2424
### Lazy Injection
2525

2626
Resolver also has a LazyInjected property wrapper. Unlike using Injected, lazily injected services are not resolved until the code attempts to access the wrapped service.
27-
```
27+
```swift
2828
class NamedInjectedViewController: UIViewController {
2929
@LazyInjected var service: XYZNameService
3030
func load() {
@@ -37,7 +37,7 @@ Note that LazyInjected is a mutating property wrapper. As such it can only be us
3737
### Weak Lazy Injection
3838

3939
Resolver also has a WeakLazyInjected property wrapper. Like LazyInjected, services are not resolved until the code attempts to access the wrapped service.
40-
```
40+
```swift
4141
class NamedInjectedViewController: UIViewController {
4242
@WeakLazyInjected var service: XYZNameService
4343
func load() {
@@ -51,13 +51,13 @@ Note that LazyInjected is a mutating property wrapper. As such it can only be us
5151

5252
You can use named service resolution using the `name` property wrapper initializer as shown below.
5353

54-
```
54+
```swift
5555
class NamedInjectedViewController: UIViewController {
5656
@Injected(name: "fred") var service: XYZNameService
5757
}
5858
```
5959
You can also update the name in code and 'on the fly' using @LazyInjected.
60-
```
60+
```swift
6161
class NamedInjectedViewController: UIViewController {
6262
@LazyInjected var service: XYZNameService
6363
var which: Bool
@@ -72,7 +72,7 @@ If you go this route just make sure you specify the name *before* accessing the
7272
### Optional injection
7373

7474
An annotation is available that supports optional resolving. If the service is not registered, then the value will be nil, otherwise it will be not nil:
75-
```
75+
```swift
7676
class InjectedViewController: UIViewController {
7777
@OptionalInjected var service: XYZService?
7878
func load() {
@@ -84,7 +84,7 @@ class InjectedViewController: UIViewController {
8484
### Injection With Protocols
8585

8686
Injecting a protocol works with all of the injection property wrappers.
87-
```
87+
```swift
8888
protocol Loader {
8989
func load()
9090
}
@@ -102,19 +102,19 @@ Registration of the class providing the protocol instance is performed exactly t
102102

103103
You can specify and resolve custom containers using Injected. Just define your custom container...
104104

105-
```
105+
```swift
106106
extension Resolver {
107107
static var custom = Resolver()
108108
}
109109
```
110110
And specify it as part of the Injected property wrapper initializer.
111-
```
111+
```swift
112112
class ContainerInjectedViewController: UIViewController {
113113
@Injected(container: .custom) var service: XYZNameService
114114
}
115115
```
116116
As with named injection, with LazyInjected you can also dynamically specifiy the desired container.
117-
```
117+
```swift
118118
class NamedInjectedViewController: UIViewController {
119119
@LazyInjected var service: XYZNameService
120120
var which: Bool

Documentation/Arguments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Why? Because property wrappers are at heart properties and they're immediately i
116116
It can't, for example, do `@Injected(args: self.editMode) var viewModel: XYZViewModel` as `self` isn't available. Swift won't allow it.
117117

118118
That said, it's possible to be sneaky about it and pass arguments using `@LazyInjected`.
119-
```
119+
```swift
120120
class NamedInjectedViewController: UIViewController {
121121
@LazyInjected var service: XYZNameService
122122
var editMode: Bool
@@ -160,7 +160,7 @@ To put that into English, it means the dependency-injection system creates and c
160160
Data is never injected.
161161

162162
If an object requires data or values created or manipulated during runtime I'd do something like the following....
163-
```
163+
```swift
164164
class DummyViewModel {
165165
func load(id: Int, editing: Bool) { }
166166
}

Documentation/Containers.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In Resolver, a resolver instance contains its registration code, its resolution
1010

1111
Inspect Resolver's code and you'll see the following.
1212

13-
```
13+
```swift
1414
public final class Resolver {
1515
public static let main: Resolver = Resolver()
1616
public static var root: Resolver = main
@@ -23,7 +23,7 @@ Resolver creates a *main* container that it uses as its default container for al
2323

2424
This basically means that when you do....
2525

26-
```
26+
```swift
2727
extension Resolver: ResolverRegistering {
2828
static func registerAllServices() {
2929
register { XYZNetworkService(session: resolve()) }
@@ -34,7 +34,7 @@ extension Resolver: ResolverRegistering {
3434

3535
You're effectively doing...
3636

37-
```
37+
```swift
3838
extension Resolver: ResolverRegistering {
3939
static func registerAllServices() {
4040
main.register { XYZNetworkService(session: root.resolve()) }
@@ -45,7 +45,7 @@ extension Resolver: ResolverRegistering {
4545

4646
The static (class) register and resolve functions simply pass the buck to main and root, respectively.
4747

48-
```
48+
```swift
4949
public static func register<Service>(_ type: Service.Type = Service.self, name: Resolver.Name? = nil,
5050
factory: @escaping ResolverFactoryArgumentsN<Service>) -> ResolverOptions<Service> {
5151
return main.register(type, name: name, factory: factory)
@@ -60,15 +60,15 @@ public static func resolve<Service>(_ type: Service.Type = Service.self, name: S
6060

6161
Creating your own container is simple, and similar to creating your own scope caches.
6262

63-
```
63+
```swift
6464
extension Resolver {
6565
static let mock = Resolver()
6666
}
6767
```
6868

6969
It could then be used as follows.
7070

71-
```
71+
```swift
7272
extension Resolver: ResolverRegistering {
7373
static func registerAllServices() {
7474
mock.register { XYZNetworkService(session: mock.resolve()) }
@@ -91,7 +91,7 @@ This implies that if root were to point to a different container, like our *mock
9191

9292
Now consider the following:
9393

94-
```
94+
```swift
9595
extension Resolver {
9696
static let mock = Resolver(parent: main)
9797

@@ -117,7 +117,7 @@ If a service is **not** found in *mock*, the *main* parent container will be se
117117

118118
One might ask why we simply don't do the following:
119119

120-
```
120+
```swift
121121
extension Resolver {
122122
static func registerAllServices() {
123123
register { XYZNetworkService(session: resolve()) }
@@ -138,7 +138,7 @@ But what if, for example, we want to keep both registrations and use the proper
138138

139139
Consider the following:
140140

141-
```
141+
```swift
142142
extension Resolver {
143143
#if DEBUG
144144
static let mock = Resolver(parent: main)
@@ -157,15 +157,15 @@ extension Resolver {
157157

158158
And then somewhere in our code we do this before we enter a given section:
159159

160-
```
160+
```swift
161161
#if DEBUG
162162
Resolver.root = Resolver.mock
163163
#end
164164
```
165165

166166
And then when exiting that section:
167167

168-
```
168+
```swift
169169
#if DEBUG
170170
Resolver.root = Resolver.main
171171
#end

Documentation/Injection.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The first injection technique is to define a interface for the injection, and in
2323

2424
#### The Class
2525

26-
```
26+
```swift
2727
class XYZViewModel {
2828

2929
lazy var fetcher: XYZFetching = getFetcher()
@@ -38,7 +38,7 @@ class XYZViewModel {
3838

3939
#### The Dependency Injection Code
4040

41-
```
41+
```swift
4242
extension XYZViewModel: Resolving {
4343
func getFetcher() -> XYZFetching { return resolver.resolve() }
4444
func getService() -> XYZService { return resolver.resolve() }
@@ -70,7 +70,7 @@ Property Injection exposes its dependencies as properties, and it's up to the De
7070

7171
#### The Class
7272

73-
```
73+
```swift
7474
class XYZViewModel {
7575

7676
var fetcher: XYZFetching!
@@ -85,7 +85,7 @@ class XYZViewModel {
8585

8686
#### The Dependency Injection Code
8787

88-
```
88+
```swift
8989
func setupMyRegistrations {
9090
register { XYZViewModel() }
9191
.resolveProperties { (resolver, model) in
@@ -120,7 +120,7 @@ A Constructor is the Java term for a Swift Initializer, but the idea is the same
120120

121121
#### The Class
122122

123-
```
123+
```swift
124124
class XYZViewModel {
125125

126126
private var fetcher: XYZFetching
@@ -141,7 +141,7 @@ class XYZViewModel {
141141

142142
#### The Dependency Injection Code
143143

144-
```
144+
```swift
145145
func setupMyRegistrations {
146146
register { XYZViewModel(fetcher: resolve(), service: resolve()) }
147147
register { XYZFetcher() as XYZFetching }
@@ -170,7 +170,7 @@ Method Injection is pretty much what it says, injecting the object needed into a
170170

171171
#### The Class
172172

173-
```
173+
```swift
174174
class XYZViewModel {
175175

176176
func load(fetcher: XYZFetching, service: XYZFetching) -> Data {
@@ -207,7 +207,7 @@ Technically, Service Locator is its own Design Pattern, distinct from Dependency
207207

208208
#### The Class
209209

210-
```
210+
```swift
211211
class XYZViewModel {
212212

213213
var fetcher: XYZFetching = Resolver.resolve()
@@ -222,7 +222,7 @@ class XYZViewModel {
222222

223223
#### The Dependency Injection Code
224224

225-
```
225+
```swift
226226
func setupMyRegistrations {
227227
register { XYZFetcher() as XYZFetching }
228228
register { XYZService() }
@@ -246,7 +246,7 @@ Annotation uses comments or other metadata to indication that dependency injecti
246246

247247
#### The Class
248248

249-
```
249+
```swift
250250
class XYZViewModel {
251251

252252
@Injected var fetcher: XYZFetching
@@ -261,7 +261,7 @@ class XYZViewModel {
261261

262262
#### The Dependency Injection Code
263263

264-
```
264+
```swift
265265
func setupMyRegistrations {
266266
register { XYZFetcher() as XYZFetching }
267267
register { XYZService() }

Documentation/Installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Resolver is available through Swift Package Manager. To install it simply include it in your package dependencies:
66

7-
```
7+
```swift
88
dependencies: [
99
.package(url: "https://github.com/hmlongco/Resolver.git", from: "1.1.2"),
1010
]
@@ -16,7 +16,7 @@ Or in Xcode via File > Swift Packages > Add Package Dependency...
1616

1717
Resolver is available through CocoaPods. To install it, simply add the following line to your Podfile:
1818

19-
```
19+
```swift
2020
pod "Resolver"
2121
```
2222

Documentation/Names.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Now the view controller gets the proper view model for the job. The `lazy var` e
121121

122122
If you're using Resolver's property wrappers for injection, you can also do the same with `@LazyInjected`.
123123

124-
```
124+
```swift
125125
class NamedInjectedViewController: UIViewController {
126126
var editMode: Bool // set, perhaps, by calling segue
127127
@LazyInjected var viewModel: XYZViewModelProtocol

Documentation/Optionals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var abc: ABCServicing? = Resolver.resolve(ABCService.self)
5858
## Optional annotation
5959

6060
An annotation is available that supports optional resolving. If the service is not registered, then the value will be nil, otherwise it will be not nil:
61-
```
61+
```swift
6262
class InjectedViewController: UIViewController {
6363
@OptionalInjected var service: XYZService?
6464
func load() {

Documentation/Registration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Let's start by adding the master injection file for the entire application.
2727

2828
Add a file named `AppDelegate+Injection.swift` to your project and add the following code:
2929

30-
```
30+
```swift
3131
import Resolver
3232

3333
extension Resolver: ResolverRegistering {
@@ -53,7 +53,7 @@ Let's say you have a group in your project folder named "NetworkServices", and y
5353

5454
Go to the NetworkServices folder and add a swift file named: `NetworkServices+Injection.swift`, then add the following to that file...
5555

56-
```
56+
```swift
5757
#import Resolver
5858

5959
extension Resolver {
@@ -67,7 +67,7 @@ extension Resolver {
6767

6868
Now, go back to your `AppDelegate+Injection.swift` file and add a reference to `registerMyNetworkServices`.
6969

70-
```
70+
```swift
7171
extension Resolver: ResolverRegistering {
7272
public static func registerAllServices() {
7373
registerMyNetworkServices()
@@ -83,7 +83,7 @@ Now, housekeeping completed, return to `NetworkServices+Injection.swift` and ad
8383

8484
Just as an example:
8585

86-
```
86+
```swift
8787
import Resolver
8888

8989
extension Resolver {

Documentation/Scopes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ If you don't want this behavior, and if every request should get its own `unique
9797

9898
This scope stores a *weak* reference to the resolved instance.
9999

100-
```
100+
```swift
101101
register { MyViewModel() }
102102
.scope(.shared)
103103
```

0 commit comments

Comments
 (0)