You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ Astroject is designed to simplify dependency management in your Swift projects.
10
10
11
11
## API Documentation
12
12
Coming Soon...
13
+
[DocC]()
13
14
14
15
## Features
15
16
-**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)
68
69
service.doSomething()
69
70
```
70
71
71
-
### Asynchronous Registration
72
+
### Asynchronous Registration and Resolution
72
73
Asynchronous registration primary supports any initializer that needs to run asynchronously. This tends to happen often with classes wrapped with @MainActor.
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.
100
101
```swift
101
102
importAstroject
@@ -195,11 +196,12 @@ let container = Container()
195
196
let instance1: MyClass =try container.resolve(MyClass.self)
196
197
197
198
// No output (same instance)
198
-
let instance2: MyClass =try container.resolve(MyClass.self) ```
199
+
let instance2: MyClass =try container.resolve(MyClass.self)
200
+
```
199
201
- 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.
200
202
```swift
201
203
try container.register(MyClass.self) { _in
202
-
MyClass()
204
+
MyClass()
203
205
}
204
206
.asWeak()
205
207
@@ -221,6 +223,7 @@ let container = Container()
221
223
// Output: MyClass initialized
222
224
let instance4: MyClass =try container.resolve(MyClass.self)
223
225
```
226
+
224
227
#### Custom Scopes
225
228
Additionally you can create your own Scopes through utilization of the `Instance` protocoland the `as` function on `any Registrable`.
226
229
```swift
@@ -232,14 +235,15 @@ class ExampleInstance: Instance {
Convenience functions can also be created by extending `Registrable`
235
-
```swift
236
-
extensionRegistrable {
237
-
@discardableResult
238
-
funcexampleInstance() ->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
+
```
243
247
244
248
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.
0 commit comments