Pilgrim - Dependency injection for Swift (iOS, OSX, Linux). Strongly typed, pure Swift successor to Typhoon.

Overview

PilgrimSplash

pilgrim.ph

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.


Quick Start

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.

Installation

CocoaPods

pod 'Pilgrim-DI'

Other installation methods (Swift Package Manager, etc) coming soon!


Sample App

Here's a sample app / starter template, to get up and running quickly.


User Guide

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.


What is Dependency Injection?

Not sure? There's an introduction on the pilgrim.ph website. Head on over and take a look. We'll meet back here.

Feedback

I'm not sure how to do [xyz]

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.

Interested in contributing?

Great! A contribution guide, along with detailed documentation will be published in the coming days.

I've found a bug, or have a feature request

Please raise a GitHub issue.


Who is using it?

Are you using Pilgrim and would like to support free & open-source software? Send us an email or PR to add your logo here.


Have you seen the light?

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.


License

Copyright (c) 2020 Pilgrim Contributors

You might also like...
Swift Ultralight Dependency Injection / Service Locator framework
Swift Ultralight Dependency Injection / Service Locator framework

Swift Ultralight Dependency Injection / Service Locator framework

Kraken - Simple Dependency Injection container for Swift. Use protocols to resolve dependencies with easy-to-use syntax!
Kraken - Simple Dependency Injection container for Swift. Use protocols to resolve dependencies with easy-to-use syntax!

Kraken Photo courtesy of www.krakenstudios.blogspot.com Introduction Kraken is a simple Dependency Injection Container. It's aimed to be as simple as

Needle - Compile-time safe Swift dependency injection framework
Needle - Compile-time safe Swift dependency injection framework

Needle is a dependency injection (DI) system for Swift. Unlike other DI frameworks, such as Cleanse, Swinject, Needle encourages hierarchical DI struc

Toledo - a dependency injection library for Swift that statically generates resolvers at compile-time.

Toledo Toledo is a dependency injection library for Swift that statically generates resolvers at compile-time. Index Features Installation Usage Licen

A new approach to Container-Based Dependency Injection for Swift and SwiftUI.
A new approach to Container-Based Dependency Injection for Swift and SwiftUI.

A new approach to Container-Based Dependency Injection for Swift and SwiftUI. Why do something new? Resolver was my first Dependency Injection system.

Container is a lightweight dependency injection framework for Swift.
Container is a lightweight dependency injection framework for Swift.

Container Container is a lightweight dependency injection framework for Swift. Installation is available in the Swift Package Manager. Swift Package M

Effortless modular dependency injection for Swift.

Inject Effortless modular dependency injection for Swift. Sometimes during the app development process we need to replace instances of classes or acto

Corridor  A Coreader-like Dependency Injection μFramework
Corridor A Coreader-like Dependency Injection μFramework

Corridor A Coreader-like Dependency Injection μFramework Table of Contents Why | Examples | Usage | Installation | Credits & License | Why In order to

Deli is an easy-to-use Dependency Injection Container that creates DI containers
Deli is an easy-to-use Dependency Injection Container that creates DI containers

Deli is an easy-to-use Dependency Injection Container that creates DI containers with all required registrations and corresponding factories.

Comments
  • 📦️ SPM support

    📦️ SPM support

    Summary

    This adds a Package.swift file for SPM support. I've essentially mirrored the pod spec file in terms of swift version, supported platform versions etc

    This covers https://github.com/appsquickly/pilgrim/issues/4

    Testing

    I tested locally using swift build and swift test (see notes) and in our app by pointing SPM to this branch

    Notes

    I updated the import module name from @testable import Pilgrim to @testable import PilgrimDI and fixed the local Xcode project to match so that tests could be run

    opened by wattson12 8
  • Getting null value exception when using in Appdelegate's didFinishLaunchingWithOptions

    Getting null value exception when using in Appdelegate's didFinishLaunchingWithOptions

    Below is the code:

    @Assembled private var dbManager: DBInterface

    override init() {
        AssemblyHolder.defaultAssemblyType = ApplicationAssembly.self
    }
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        print(appSettingsManager.getAppCenterKey())
    
        AppCenter.start(withAppSecret: Bundle.main.object(forInfoDictionaryKey: "app_center_key") as? String, services:[
          Analytics.self,
          Crashes.self
        ])
        
        return false
    }
    
    
    And by using this, I am getting an exception at Assembled.swift's wrappedValue get 
    
    opened by zayantharani 2
  • 📦️ Update SPM minimum deployment targets

    📦️ Update SPM minimum deployment targets

    Summary

    The current Package.swift is targeting iOS 14 and macOS 11 while the pod spec is targeting 9 and 10.10. This change brings the package in line with podspec

    opened by wattson12 1
  • Assembled() returns no error message for component that does not resolve

    Assembled() returns no error message for component that does not resolve

    Assembled wrapper requires explicitly declaring bindings, eg:

    public override func makeBindings() {
            makeInjectable(viewCoordinator, byType: ViewCoordinator.self)
    }
    

    If a component is not resolved, no meaningful error is thrown (instead unexpected nil value).

    opened by jasperblues 1
Owner
AppsQuick.ly
We create beautiful digital media and mobile applications.
AppsQuick.ly
Injection - Dependency injection using property wrappers

Dependency injection using property wrappers. Registering types: // injecting a

Alejandro Ramirez 3 Mar 14, 2022
Dependency Injection framework for Swift (iOS/macOS/Linux)

Declarative, easy-to-use and safe Dependency Injection framework for Swift (iOS/macOS/Linux) Features Dependency declaration via property wrappers or

Scribd 684 Dec 12, 2022
ViperServices - Simple dependency injection container for services written for iOS in swift supporting boot order

ViperServices Introduction ViperServices is dependency injection container for iOS applications written in Swift. It is more lightweight and simple in

Siarhei Ladzeika 5 Dec 8, 2022
CarbonGraph - A Swift dependency injection / lookup framework for iOS

CarbonGraph is a Swift dependency injection / lookup framework for iOS. You can

Baidu 244 Jan 4, 2023
DIContainer Swift is an ultra-light dependency injection container made to help developers to handle dependencies easily. It works with Swift 5.1 or above.

?? DIContainer Swift It is an ultra-light dependency injection container made to help developers to handle dependencies easily. We know that handle wi

Victor Carvalho Tavernari 10 Nov 23, 2022
Injector - A Swift package for simple dependency injection that also supports Swift UI previews

A Swift package for simple dependency injection that also supports Swift UI prev

null 6 Aug 9, 2022
Cleanse is a dependency injection framework for Swift.

Cleanse - Swift Dependency Injection Cleanse is a dependency injection framework for Swift. It is designed from the ground-up with developer experienc

Square 1.7k Dec 16, 2022
DIKit Dependency Injection Framework for Swift, inspired by KOIN.

DIKit Dependency Injection Framework for Swift, inspired by KOIN. Basically an implementation of service-locator pattern, living within the applicatio

null 95 Dec 22, 2022
Tranquillity is a lightweight but powerful dependency injection library for swift.

DITranquillity Tranquillity is a lightweight but powerful dependency injection library for swift. The name "Tranquillity" laid the foundation in the b

Ivlev Alexander 393 Dec 24, 2022
Swinject is a lightweight dependency injection framework for Swift.

Swinject Swinject is a lightweight dependency injection framework for Swift. Dependency injection (DI) is a software design pattern that implements In

null 5.6k Dec 31, 2022