[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-6776":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":9,"pushedAt":9,"updatedAt":28,"readmeContent":29,"aiSummary":30,"trendingCount":15,"starSnapshotCount":15,"syncStatus":31,"lastSyncTime":32,"discoverSource":33},6776,"Swinject","Swinject\u002FSwinject","Dependency injection framework for Swift with iOS\u002FmacOS\u002FLinux","",null,"Swift",6710,544,99,58,0,5,39.21,"MIT License",false,"master",[22,23,24,25,26,27],"dependency-injection","di-container","inversion-of-control","ioc-container","ios","swift","2026-06-12 02:01:29","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Favatars0.githubusercontent.com\u002Fu\u002F13637225?v=3&s=600\" width=\"33%\">\n\u003C\u002Fp>\n\nSwinject\n========\n\n![Github Actions](https:\u002F\u002Fgithub.com\u002F1ucas\u002FSwinject\u002Factions\u002Fworkflows\u002FProject%20Testing.yml\u002Fbadge.svg?branch=master)\n[![Carthage compatible](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCarthage-compatible-4BC51D.svg?style=flat)](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage)\n[![CocoaPods Version](https:\u002F\u002Fimg.shields.io\u002Fcocoapods\u002Fv\u002FSwinject.svg?style=flat)](http:\u002F\u002Fcocoapods.org\u002Fpods\u002FSwinject)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fcocoapods\u002Fl\u002FSwinject.svg?style=flat)](http:\u002F\u002Fcocoapods.org\u002Fpods\u002FSwinject)\n[![Platforms](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fplatform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-lightgrey.svg)](http:\u002F\u002Fcocoapods.org\u002Fpods\u002FSwinject)\n[![Swift Version](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSwift-4.2--5.4-F16D39.svg?style=flat)](https:\u002F\u002Fdeveloper.apple.com\u002Fswift)\n[![Reviewed by Hound](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FReviewed_by-Hound-8E64B0.svg)](https:\u002F\u002Fhoundci.com)\n\nSwinject is a lightweight [dependency injection](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDependency_injection) framework for Swift.\n\nDependency injection (DI) is a software design pattern that implements Inversion of Control (IoC) for resolving dependencies. In the pattern, Swinject helps your app split into loosely-coupled components, which can be developed, tested and maintained more easily. Swinject is powered by the Swift generic type system and first class functions to define dependencies of your app simply and fluently.\n\nSwinject is maintained by the [Faire Wholesale Inc.](https:\u002F\u002Fgithub.com\u002FFaire?view_as=public) mobile platform team.\n\n## Features\n\n- [x] [Pure Swift Type Support](.\u002FDocumentation\u002FREADME.md#user-content-pure-swift-type-support)\n- [x] [Injection with Arguments](.\u002FDocumentation\u002FDIContainer.md#registration-with-arguments-to-di-container)\n- [x] [Initializer\u002FProperty\u002FMethod Injections](.\u002FDocumentation\u002FInjectionPatterns.md)\n- [x] [Initialization Callback](.\u002FDocumentation\u002FInjectionPatterns.md#user-content-initialization-callback)\n- [x] [Circular Dependency Injection](.\u002FDocumentation\u002FCircularDependencies.md)\n- [x] [Object Scopes as None (Transient), Graph, Container (Singleton) and Hierarchy](.\u002FDocumentation\u002FObjectScopes.md)\n- [x] Support of both Reference and [Value Types](.\u002FDocumentation\u002FMisc.md#value-types)\n- [x] [Self-registration (Self-binding)](.\u002FDocumentation\u002FMisc.md#self-registration-self-binding)\n- [x] [Container Hierarchy](.\u002FDocumentation\u002FContainerHierarchy.md)\n- [x] [Thread Safety](.\u002FDocumentation\u002FThreadSafety.md)\n- [x] [Modular Components](.\u002FDocumentation\u002FAssembler.md)\n\n## Extensions\n\n- **[SwinjectPropertyLoader](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinjectPropertyLoader)**: Loading property values from resources.\n- **[SwinjectStoryboard](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinjectStoryboard)**: Automatic dependency injection via Storyboard.\n- **[Swinject-CodeGen](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinject-CodeGen)**: Type-safe code generation of `Container` from a CSV\u002FYAML file defining dependencies.\n- **[SwinjectAutoregistration](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinjectAutoregistration)**: Automatic registration of services by leveraging the Swift Generics.\n\n## Requirements\n\n- iOS 11.0+ \u002F Mac OS X 10.13+ \u002F watchOS 4.0+ \u002F tvOS 11.0+\n- Xcode 14.3+\n- Swift 4.2+\n- Carthage 0.18+ (if you use)\n- CocoaPods 1.1.1+ (if you use)\n\n## Installation\n\nSwinject is available through [Carthage](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage), [CocoaPods](https:\u002F\u002Fcocoapods.org), or [Swift Package Manager](https:\u002F\u002Fswift.org\u002Fpackage-manager\u002F).\n\n### Carthage\n\nTo install Swinject with Carthage, add the following line to your `Cartfile`.\n\n```\ngithub \"Swinject\u002FSwinject\"\n\n# Uncomment if you use SwinjectStoryboard\n# github \"Swinject\u002FSwinjectStoryboard\"\n```\n\nThen run `carthage update --no-use-binaries` command or just `carthage update`. For details of the installation and usage of Carthage, visit [its project page](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage).\n\n\n### CocoaPods\n\nTo install Swinject with CocoaPods, add the following lines to your `Podfile`.\n\n```ruby\nsource 'https:\u002F\u002Fgithub.com\u002FCocoaPods\u002FSpecs.git'\nplatform :ios, '11.0' # or platform :osx, '10.13' if your target is OS X.\nuse_frameworks!\n\npod 'Swinject'\n\n# Uncomment if you use SwinjectStoryboard\n# pod 'SwinjectStoryboard'\n```\n\nThen run `pod install` command. For details of the installation and usage of CocoaPods, visit [its official website](https:\u002F\u002Fcocoapods.org).\n\n### Swift Package Manager\n\nin `Package.swift` add the following:\n\n```swift\ndependencies: [\n    \u002F\u002F Dependencies declare other packages that this package depends on.\n    \u002F\u002F .package(url: \u002F* package url *\u002F, from: \"1.0.0\"),\n    .package(url: \"https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinject.git\", from: \"2.8.0\")\n],\ntargets: [\n    .target(\n        name: \"MyProject\",\n        dependencies: [..., \"Swinject\"]\n    )\n    ...\n]\n```\n\n## Documentation\n\n- [Technical documents](.\u002FDocumentation) including patterns of dependency injection and examples.\n- [API reference](http:\u002F\u002Fcocoadocs.org\u002Fdocsets\u002FSwinject\u002F)\n\n## Basic Usage\n\nFirst, register a service and component pair to a `Container`, where the component is created by the registered closure as a factory. In this example, `Cat` and `PetOwner` are component classes implementing `Animal` and `Person` service protocols, respectively.\n\n```swift\nlet container = Container()\ncontainer.register(Animal.self) { _ in Cat(name: \"Mimi\") }\ncontainer.register(Person.self) { r in\n    PetOwner(pet: r.resolve(Animal.self)!)\n}\n```\n\nThen get an instance of a service from the container. The person is resolved to a pet owner, and playing with the cat named Mimi!\n\n```swift\nlet person = container.resolve(Person.self)!\nperson.play() \u002F\u002F prints \"I'm playing with Mimi.\"\n```\n\nWhere definitions of the protocols and classes are\n\n```swift\nprotocol Animal {\n    var name: String? { get }\n}\n\nclass Cat: Animal {\n    let name: String?\n\n    init(name: String?) {\n        self.name = name\n    }\n}\n```\n\nand\n\n```swift\nprotocol Person {\n    func play()\n}\n\nclass PetOwner: Person {\n    let pet: Animal\n\n    init(pet: Animal) {\n        self.pet = pet\n    }\n\n    func play() {\n        let name = pet.name ?? \"someone\"\n        print(\"I'm playing with \\(name).\")\n    }\n}\n```\n\nNotice that the `pet` of `PetOwner` is automatically set as the instance of `Cat` when `Person` is resolved to the instance of `PetOwner`. If a container already set up is given, you do not have to care what are the actual types of the services and how they are created with their dependency.\n\n## Where to Register Services\n\nServices must be registered to a container before they are used. The typical registration approach will differ depending upon whether you are using `SwinjectStoryboard` or not.\n\nThe following view controller class is used in addition to the protocols and classes above in the examples below.\n\n```swift\nclass PersonViewController: UIViewController {\n    var person: Person?\n}\n```\n\n### With SwinjectStoryboard\n\nImport SwinjectStoryboard at the top of your swift source file.\n\n```swift\nimport SwinjectStoryboard\n```\n\nServices should be registered in an extension of `SwinjectStoryboard` if you use `SwinjectStoryboard`. Refer to [the project page of SwinjectStoryboard](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinjectStoryboard) for further details.\n\n```swift\nextension SwinjectStoryboard {\n    @objc class func setup() {\n        defaultContainer.register(Animal.self) { _ in Cat(name: \"Mimi\") }\n        defaultContainer.register(Person.self) { r in\n            PetOwner(pet: r.resolve(Animal.self)!)\n        }\n        defaultContainer.register(PersonViewController.self) { r in\n            let controller = PersonViewController()\n            controller.person = r.resolve(Person.self)\n            return controller\n        }\n    }\n}\n```\n\n### Without SwinjectStoryboard\n\nIf you do not use `SwinjectStoryboard` to instantiate view controllers, services should be registered to a container in your application's `AppDelegate`. Registering before exiting `application:didFinishLaunchingWithOptions:` will ensure that the services are setup appropriately before they are used.\n\n```swift\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n    var window: UIWindow?\n    let container: Container = {\n        let container = Container()\n        container.register(Animal.self) { _ in Cat(name: \"Mimi\") }\n        container.register(Person.self) { r in\n            PetOwner(pet: r.resolve(Animal.self)!)\n        }\n        container.register(PersonViewController.self) { r in\n            let controller = PersonViewController()\n            controller.person = r.resolve(Person.self)\n            return controller\n        }\n        return container\n    }()\n\n    func application(\n        _ application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {\n\n        \u002F\u002F Instantiate a window.\n        let window = UIWindow(frame: UIScreen.main.bounds)\n        window.makeKeyAndVisible()\n        self.window = window\n\n        \u002F\u002F Instantiate the root view controller with dependencies injected by the container.\n        window.rootViewController = container.resolve(PersonViewController.self)\n\n        return true\n    }\n}\n```\n\nNotice that the example uses a convenience initializer taking a closure to register services to the new instance of `Container`.\n\n## Play in Playground!\n\nThe project contains `Sample-iOS.playground` to demonstrate the features of Swinject. Download or clone the project, run the playground, modify it, and play with it to learn Swinject.\n\nTo run the playground in the project, first build the project, then select `Editor > Execute Playground` menu in Xcode.\n\n## Example Apps\n\nSome example apps using Swinject can be found on [GitHub](https:\u002F\u002Fgithub.com\u002Fsearch?o=desc&q=swinject&s=updated&type=Repositories).\n\n## Blog Posts\n\nThe following blog posts introduce the concept of dependency injection and Swinject.\n\n- [Dependency Injection Tutorial for iOS: Getting Started](https:\u002F\u002Fwww.raywenderlich.com\u002F14223279-dependency-injection-tutorial-for-ios-getting-started) *by [Irina Galata](https:\u002F\u002Fwww.raywenderlich.com\u002Fu\u002Fgalata)*\n- [Swinject Tutorial for iOS: Getting Started](https:\u002F\u002Fwww.raywenderlich.com\u002F17-swinject-tutorial-for-ios-getting-started) *by [Gemma Barlow](https:\u002F\u002Fwww.raywenderlich.com\u002Fu\u002Fgemmakbarlow)*\n- [iOS Dependency Injection Using Swinject](https:\u002F\u002Fmedium.com\u002Fflawless-app-stories\u002Fios-dependency-injection-using-swinject-9c4ceff99e41) *by [Ali Akhtar](https:\u002F\u002Fali-akhtar.medium.com)*\n- [DI in iOS: Complete guide](https:\u002F\u002Fmedium.com\u002Fits-tinkoff\u002Fdi-in-ios-complete-guide-cd76a079d2d) *by [Vitaly Batrakov](https:\u002F\u002Fmedium.com\u002F@batrakov.vitaly)*\n\nThanks the authors!\n\n## Contribution Guide\n\nA guide to [submit issues](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinject\u002Fissues), to ask general questions, or to [open pull requests](https:\u002F\u002Fgithub.com\u002FSwinject\u002FSwinject\u002Fpulls) is [here](CONTRIBUTING.md).\n\n## Question?\n\n- [Stack Overflow](https:\u002F\u002Fstackoverflow.com\u002Fquestions\u002Ftagged\u002Fswinject) we are trying to monitor questions tagged `swinject`\n\n## Credits\n\nThe DI container features of Swinject are inspired by:\n\n- [Ninject](http:\u002F\u002Fninject.org) - [Enkari, Ltd](https:\u002F\u002Fgithub.com\u002Fenkari) and [the Ninject project contributors](https:\u002F\u002Fgithub.com\u002Fninject\u002FNinject\u002Fgraphs\u002Fcontributors).\n- [Autofac](http:\u002F\u002Fautofac.org) - [Autofac Project](https:\u002F\u002Fgithub.com\u002Fautofac\u002FAutofac).\n\nand highly inspired by:\n\n- [Funq](https:\u002F\u002Fgithub.com\u002Fkzu\u002Ffunq) - [Daniel Cazzulino](https:\u002F\u002Fgithub.com\u002Fkzu).\n\n## License\n\nMIT license. See the [LICENSE file](LICENSE) for details.\n","Swinject 是一个轻量级的 Swift 依赖注入框架，支持 iOS、macOS 和 Linux 平台。它利用 Swift 的泛型系统和一等函数来简洁流畅地定义应用中的依赖关系，帮助开发者将应用程序拆分为松耦合的组件，从而提高代码的可测试性和可维护性。Swinject 支持多种注入模式（如初始化器、属性和方法注入），并提供了灵活的对象作用域管理（包括瞬时、单例等）。此外，它还具备处理循环依赖的能力，并且支持线程安全操作。该框架适用于需要提升模块化程度和降低组件间耦合度的各种规模的 Swift 项目中。",2,"2026-06-11 03:08:48","top_language"]