| name | Dependency Injection Setup |
| description | Add new services to DIContainer, create protocol-based implementations, set up singletons or factories for Leavn app dependency injection |
| allowed-tools | Read, Edit, Grep |
Dependency Injection Setup
Instructions
Add new services to Leavn's DIContainer:
-
Create service protocol:
public protocol MyServiceProtocol {
func doSomething() async throws -> Result
}
-
Create implementation:
public final class MyServiceLive: MyServiceProtocol {
public init() { }
public func doSomething() async throws -> Result {
}
}
-
Register in DIContainer:
private lazy var _myService = MyServiceLive()
var myService: MyServiceProtocol {
_myService
}
var myService: MyServiceProtocol {
MyServiceLive()
}
-
Use in ViewModels:
let service = DIContainer.shared.myService
Use this skill when: Creating new service, adding dependency, setting up DI, refactoring to protocol-oriented design