Agent skill

Dependency Injection Setup

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

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/dependency-injection-setup

SKILL.md

Dependency Injection Setup

Instructions

Add new services to Leavn's DIContainer:

  1. Create service protocol:

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

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

    swift
    // 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:

    swift
    let service = DIContainer.shared.myService
    

Use this skill when: Creating new service, adding dependency, setting up DI, refactoring to protocol-oriented design

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results