{"id":25820645,"url":"https://github.com/stanfeldman/propertyinjector","last_synced_at":"2026-05-25T16:34:44.789Z","repository":{"id":62451189,"uuid":"286065363","full_name":"stanfeldman/PropertyInjector","owner":"stanfeldman","description":"Property dependency injection framework for Swift.","archived":false,"fork":false,"pushed_at":"2023-10-22T15:41:23.000Z","size":241,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-21T18:20:26.108Z","etag":null,"topics":["dependency-injection","injection","injection-framework","ios","property-wrapper","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stanfeldman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-08T15:06:43.000Z","updated_at":"2020-09-18T03:14:29.000Z","dependencies_parsed_at":"2025-02-28T09:58:31.205Z","dependency_job_id":"99f122c9-449c-473e-9269-2cfbe0738d5e","html_url":"https://github.com/stanfeldman/PropertyInjector","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/stanfeldman/PropertyInjector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfeldman%2FPropertyInjector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfeldman%2FPropertyInjector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfeldman%2FPropertyInjector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfeldman%2FPropertyInjector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanfeldman","download_url":"https://codeload.github.com/stanfeldman/PropertyInjector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfeldman%2FPropertyInjector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285986015,"owners_count":27265853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-23T02:00:06.149Z","response_time":135,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","injection","injection-framework","ios","property-wrapper","swift"],"created_at":"2025-02-28T09:58:23.885Z","updated_at":"2025-11-23T17:02:52.901Z","avatar_url":"https://github.com/stanfeldman.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PropertyInjector\n\n\u003ca href=\"https://swift.org\"\u003e\u003cimg src=\"https://img.shields.io/badge/language-Swift%205.1+-ee5137.svg\" alt=\"Language\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://developer.apple.com/ios\"\u003e\u003cimg src=\"https://img.shields.io/badge/platform-iOS%2011+-000000.svg\" alt=\"Platform\" /\u003e\u003c/a\u003e\n[![Version](https://img.shields.io/cocoapods/v/PropertyInjector.svg?style=flat)](https://cocoapods.org/pods/PropertyInjector)\n\n## Why should I use PropertyInjector?\nDependency injection, in general, is beneficial for your application because it promotes loosely coupled architecture and improves testability. There are several ways of implementing dependency injection, but I believe **property dependency injection is the most versatile and easy to use** one. This library is an implementation of property dependency injection where you just need to **declare your dependencies** and **use them as properties** in your classes. No constructor parameters, no extra code.\n\n## Getting started\n\n### Install the library\n\nFor Cocoapods, add the following line to your Podfile:\n\n```ruby\npod 'PropertyInjector'\n```\n\nFor Carthage, add the following line to your Cartfile:\n\n```ruby\ngithub \"stanfeldman/PropertyInjector\"\n```\n\n### Register your dependencies\n\nYou need to make sure that your dependencies get registered before they are injected. You can create a manager class and register the dependencies in its constructor.\n\n```swift\nclass DependencyManager {\n    init() {\n        DependencyResolver.register {\n            $0.singleton(MyDependency())\n            // or\n            $0.singleton(MyInterface.self, MyImplementation())\n        }\n    }\n}\n```\n\nAnd add this manager to your `AppDelegate` for UIKit projects and `App` object for SwiftUI projects.\n\n```swift\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n    private let dependencyManager = DependencyManager()\n}\n```\n\n### Inject your dependencies\n\nJust declare your dependency object as a property and add `@Inject` property wrapper. The dependency will be lazily resolved when the object is used.\n\n```swift\nclass ViewController: UIViewController {\n    @Inject private var dependency: MyDependency\n}\n```\n\n## Features\n\n### Resolution strategies\n\nThere are 2 supported resolution strategies:\n\n* `factory` creates your dependency every time it is resolved\n* `singleton` creates your dependency only once and reuses the instance\n\n```swift\nDependencyResolver.register {\n    $0.factory(MyDependency())\n    $0.singleton(MyDependency())\n}\n```\n\n### Dependency parameters\n\nYou can register a dependency with parameters.\n\n```swift\nDependencyResolver.register {\n    $0.factory(MyDependency.self) { parameters in\n        return MyDependency(name: parameters[\"name\"] as! String)\n    }\n}\n```\n\nAnd then resolve it using some parameters:\n\n```swift\n@Inject(with: [\"name\": \"Boris\"]) private var dependency: MyDependency\n```\n\nor\n\n```swift\nlet sub2: SubDependency2 = DependencyResolver.resolve(with: [\"name\": \"Boris\"])\n```\n\n### Manual dependency resolution\n\nAutomatic property injection using `@Inject` is preferable, but it is possible to manually resolve a dependency.\n\n```swift\nclass ViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        let dependency1: MyDependency1 = DependencyResolver.resolve()\n        let dependency2: MyDependency2 = DependencyResolver.resolve(with: [\"uuid\": UUID().uuidString])\n    }\n}\n```\n\n### Circular dependencies\n\nDependencies are resolved on demand so there is no problem injecting class B into class A and class A into class B as long as both dependencies are not used in their constructors.\n\n### Optionals resolution\n\nPropertyInjector will try to resolve an unwrapped type for optionals.\n\n\n```swift\nclass ViewController: UIViewController {\n    @Inject private var dependency: MyDependency? // will try to resolve as MyDependency\n    @Inject private var dependency: MyDependency! // the same\n}\n```\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## License\n\nPropertyInjector is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanfeldman%2Fpropertyinjector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanfeldman%2Fpropertyinjector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanfeldman%2Fpropertyinjector/lists"}