Skip to content

WeaveDIModern Dependency Injection for Swift

High-performance DI framework with Swift Concurrency support

WeaveDI

Quick Example

swift
import WeaveDI

// 1. Bootstrap dependencies at app startup
await WeaveDI.Container.bootstrap { container in
    container.register(UserServiceProtocol.self) {
        UserService()
    }

    container.register(\.userRepository) {
        UserRepositoryImpl()
    }
}

// 2. Use property wrappers for injection
class ViewController {
    @Inject var userService: UserServiceProtocol?
    @Factory var dataProcessor: DataProcessor

    func loadUserData() async {
        guard let service = userService else { return }
        let userData = await service.fetchUser()
        updateUI(with: userData)
    }
}

// 3. Modern async/await support
let userService = await UnifiedDI.resolve(UserService.self)
let userData = await userService?.fetchUserData()

Performance Metrics

ScenarioLegacy DIWeaveDI 3.2.0Improvement
Single dependency resolution0.8ms0.2ms75%
Complex dependency graph15.6ms3.1ms80%
MainActor UI update3.1ms0.6ms81%

Why WeaveDI?

WeaveDI 3.2.0 is designed for modern Swift applications, providing:

  • Support for iOS 15.0+, macOS 14.0+, watchOS 8.0+, tvOS 15.0+
  • Swift Concurrency first-class integration
  • Actor model optimization
  • Zero-cost abstraction in release builds
  • Comprehensive testing support

A framework for Swift developers

Released under the MIT License.