Pilgrim is a dependency injection library for Swift with the following features:
- Minimal runtime-only library that works with pure Swift (structs, classes, protocols) as well as ObjC base classes, when necessary.
- Easy to install. Works on iOS, Mac & Linux. No compile-time weaving required.
- Type safe. No reflection or ObjC runtime, because it is pure swift. (Uses higher-order functions.)
- Lifecycles management:
shared
,weakShared
,objectGraph
(a DI concept introduced by Typhoon, for desktop and pocket apps) &unshared
. - Can be used with SwiftUI, UIKit and Cocoa based apps.
- Simple and flexible. For example, it is easy to have two injectable instances that conform to the same protocol.
- Provides the notion of a composition root in which the key actors, and their interactions in an application architecture are defined as a graph. This is where your app's architectural story is told. Assembled instances can then be injected into top level classes, such as a view controller, in a UIKit app, using property wrappers.
- Runtime args. Can act as a factory for emitting new instances derived from a mix of runtime parameters and key architectural actors.
- Official successor to Typhoon and based on the excellent FieryCrucible by jkolb.
You can use Pilgrim in apps that employ the object-oriented programming paradigm or that mix object-oriented and functional styles.
Want to start applying dependency injection to your code in two minutes? Follow the Quick Start guide!
class AppDelegate: UIResponder, UIApplicationDelegate {
@Assembled var assembly: ApplicationAssembly
@Assembled var cityRepo: CityRepository
@Assembled var rootViewController: RootViewController
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
window = assembly.window()
window?.makeKeyAndVisible()
if (cityRepo.loadSelectedCity() == nil) {
rootViewController.showCitiesListController()
}
return true
}
}
Here's how your code might look, when you're done with the quick start.
pod 'Pilgrim-DI'
Other installation methods (Swift Package Manager, etc) coming soon!
Here's a sample app / starter template, to get up and running quickly.
The best way to get up and running is to try the quick start and sample app. After that the User Guide is your reference.
Not sure? There's an introduction on the pilgrim.ph website. Head on over and take a look. We'll meet back here.
If you can't find what you need in the Quick Start or User Guides, please post a question on StackOverflow, using the pilgrim tag.
Great! A contribution guide, along with detailed documentation will be published in the coming days.
Please raise a GitHub issue.
Are you using Pilgrim and would like to support free & open-source software? Send us an email or PR to add your logo here.
Pilgrim is a non-profit, community driven project. We only ask that if you've found it useful to star us on Github or send a tweet mentioning us (@doctor_cerulean). If you've written a Pilgrim related blog or tutorial, or published a new Pilgrim-powered app, we'd certainly be happy to hear about that too.
Pilgrim is sponsored and led by AppsQuick.ly with contributions from around the world.
Copyright (c) 2020 Pilgrim Contributors