Skip to content

Drip is a simple dependency injection (DI) system for Swift. 🚧 WARNING!: experimental implementation 🚧

Notifications You must be signed in to change notification settings

theangelperalta/drip

Repository files navigation

Drip

The Drip framework is a lightweight dependency injection framework (in terms of the API exposed to the client), has a relatively simple integration process (minimize XCode project modifications), easy to debug, and also robust, dealing gracefully with errors when they do arise. Lastly, well covered with unit testing. All this made with Swift for Swift.


Getting Started

Drip primarily uses SwiftPM as its build tool, so we recommend using that as well. If you want to depend on Drip in your own project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/Angel-Cortez/Drip", from: "0.0.1")
]

🚧 WARNING!: experimental implementation 🚧

  • Depedency Resoultion - functions, classes, and structs
  • Code generation
  • Circular Dependency detection

Usage

Defining basic Components

// ^->RootComponent
class RootComponent: OmegaComponent {
    /// The singleton instance.
    public static let instance = RootComponent()
}
// ^->RootComponent->AComponent
class AComponent: Component {
    /// The singleton instance.
    public static let instance = AComponent(parent: RootComponent.instance)
}

Providing Dependencies

__Registry.instance.registerDependencyProviderFactory(for: AComponent.instance.get(NetworkManager.self)) {
    return NewNetworkManager() as AnyObject
}

Dependency Resolution in class or struct

class ViewController {
    @Inject(AComponent.instance.get(NetworkManager.self))
    var manager: NetworkManager?
}

About

Drip is a simple dependency injection (DI) system for Swift. 🚧 WARNING!: experimental implementation 🚧

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages