Skip to content

Commit 1103c53

Browse files
committed
feat: Error Handling
1 parent eaed78a commit 1103c53

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Astroject is designed to simplify dependency management in your Swift projects.
1010

1111
## API Documentation
1212
Coming Soon...
13+
[DocC]()
1314

1415
## Features
1516
- **Synchronous and Asynchronous Registrations:** Register dependencies with both synchronous and asynchronous factory closures.
@@ -68,7 +69,7 @@ let service: Service = try container.resolve(Service.self)
6869
service.doSomething()
6970
```
7071

71-
### Asynchronous Registration
72+
### Asynchronous Registration and Resolution
7273
Asynchronous registration primary supports any initializer that needs to run asynchronously. This tends to happen often with classes wrapped with @MainActor.
7374

7475
```swift
@@ -95,7 +96,7 @@ let asyncService: AsyncService = try await container.resolveAsync(AsyncService.s
9596
asyncService.doWork()
9697
```
9798

98-
### Named Registrations
99+
### Named Registrations and Resolution
99100
Additionally with Synchronous or Asynchronous Registrations you can provide a name attribute to ensure the registration is uniquely stored when storing the same type more than once.
100101
```swift
101102
import Astroject
@@ -195,11 +196,12 @@ let container = Container()
195196
let instance1: MyClass = try container.resolve(MyClass.self)
196197

197198
// No output (same instance)
198-
let instance2: MyClass = try container.resolve(MyClass.self) ```
199+
let instance2: MyClass = try container.resolve(MyClass.self)
200+
```
199201
- Weak - As long as you retain an instance to the object the instance remains in the container when asked for. If you have no references to the class then container will deallocate its reference.
200202
```swift
201203
try container.register(MyClass.self) { _ in
202-
MyClass()
204+
MyClass()
203205
}
204206
.asWeak()
205207

@@ -221,6 +223,7 @@ let container = Container()
221223
// Output: MyClass initialized
222224
let instance4: MyClass = try container.resolve(MyClass.self)
223225
```
226+
224227
#### Custom Scopes
225228
Additionally you can create your own Scopes through utilization of the `Instance` protocol and the `as` function on `any Registrable`.
226229
```swift
@@ -232,14 +235,15 @@ class ExampleInstance: Instance {
232235
container.register(Int.self) { _ in 42 }.as(ExampleInstance())
233236
```
234237
Convenience functions can also be created by extending `Registrable`
235-
```swift
236-
extension Registrable {
237-
@discardableResult
238-
func exampleInstance() -> Self {
239-
self.as(ExampleInstance())
240-
}
241-
}
242-
```
238+
239+
```swift
240+
extension Registrable {
241+
@discardableResult
242+
func exampleInstance() -> Self {
243+
self.as(ExampleInstance())
244+
}
245+
}
246+
```
243247

244248
If you need a combination of multiple scopes just create the scopes you need then add them to our `Composite` Instance object. `Composite` takes the first instance not nil from a list of `Instance` objects.
245249
```swift

0 commit comments

Comments
 (0)