Agent Skills: Dependency Injection Setup

Add new services to DIContainer, create protocol-based implementations, set up singletons or factories for Leavn app dependency injection

UncategorizedID: willsigmon/sigstack/dependency-injection-setup

Install this agent skill to your local

pnpm dlx add-skill https://github.com/willsigmon/sigstack/tree/HEAD/plugins/app-dev/skills/dependency-injection-setup

Skill Files

Browse the full folder contents for dependency-injection-setup.

Download Skill

Loading file tree…

plugins/app-dev/skills/dependency-injection-setup/SKILL.md

Skill Metadata

Name
Dependency Injection Setup
Description
Add new services to DIContainer, create protocol-based implementations, set up singletons or factories for Leavn app dependency injection

Dependency Injection Setup

Instructions

Add new services to Leavn's DIContainer:

  1. Create service protocol:

    // Services/MyDomain/MyServiceProtocol.swift
    public protocol MyServiceProtocol {
        func doSomething() async throws -> Result
    }
    
  2. Create implementation:

    // Services/MyDomain/MyServiceLive.swift
    public final class MyServiceLive: MyServiceProtocol {
        public init() { }
    
        public func doSomething() async throws -> Result {
            // Implementation
        }
    }
    
  3. Register in DIContainer:

    // For singletons (stateful services):
    private lazy var _myService = MyServiceLive()
    var myService: MyServiceProtocol {
        _myService
    }
    
    // For factories (stateless services):
    var myService: MyServiceProtocol {
        MyServiceLive()
    }
    
  4. 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