InfomaniakDI

2.0.1

Minimalist dependency injection mechanism
Infomaniak/swift-dependency-injection

What's New

2.0.1 - Compatibility for SPM 5.6

2023-11-16T13:43:19Z

What's Changed

Full Changelog: 2.0.0...2.0.1

InfomaniakDI

Minimalist dependency injection mechanism written in pure Swift.

Support any first party Swift platfom. [ iOS / iPadOS / watchOS / macOS / Linux ]

Well tested. Used in production across the Infomaniak iOS Apps.

Property wrapper based with @LazyInjectService and @InjectService.

Optimised to work well with SwiftUI Views.

Features

  • Efficient SwiftUI. @(Lazy)InjectService will not re-resolve, when used as a property, on a View redraw.
  • Good integration test coverage
  • Pure Swift Type Support
  • Thread safety
  • Injection by name
  • Injection with Arguments
  • Lazy init (with @LazyInjectService)

Roadmap

  • Optionals
  • Multiple containers

Requirements

  • Swift 5.6 +
  • SPM

Setup

Early on in the lifecycle of your app, you want to write something like this :

import InfomaniakDI

[]

let factory = Factory(type: SomeService.self) { _, _ in
   SomeService()
}

do {
    try SimpleResolver.sharedResolver.store(factory: factory)
}
catch {
    FatalError("unexpected DI error \(error)")
}

later on, when you want to resolve a service use the property wrapper like so:

@InjectService var injected: SomeService

Injection will be performed at the init time of the owner of the property.

Use @LazyInjectService for resolution at first use of the wrapped property. Prefer @LazyInjectService when used as a property.

Documentation

Checkout ITSimpleReslover.swift for more advanced examples.

Licence

This package is available under the permissive ApacheV2 licence for you to enjoy.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Dec 12 2024 07:45:23 GMT-1000 (Hawaii-Aleutian Standard Time)