{"id":20064876,"url":"https://github.com/baidu/carbongraph","last_synced_at":"2025-05-16T17:00:24.775Z","repository":{"id":43340826,"uuid":"452175796","full_name":"baidu/CarbonGraph","owner":"baidu","description":"A Swift dependency injection / lookup framework for iOS","archived":false,"fork":false,"pushed_at":"2024-11-04T06:49:24.000Z","size":2532,"stargazers_count":255,"open_issues_count":0,"forks_count":20,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-03T15:09:54.777Z","etag":null,"topics":["component-architecture","dependency-injection","di-container","dsl","ioc","ioc-container","ios","objective-c","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/baidu.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":"2022-01-26T07:13:57.000Z","updated_at":"2024-11-15T07:04:01.000Z","dependencies_parsed_at":"2024-06-19T20:03:50.652Z","dependency_job_id":"2576002a-ee59-45c9-86a8-5e93b00c96b6","html_url":"https://github.com/baidu/CarbonGraph","commit_stats":{"total_commits":54,"total_committers":4,"mean_commits":13.5,"dds":0.2407407407407407,"last_synced_commit":"2ae12a0b87e7cb2a0b9ff0a995df0f302cef0fc1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FCarbonGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FCarbonGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FCarbonGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FCarbonGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baidu","download_url":"https://codeload.github.com/baidu/CarbonGraph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590261,"owners_count":21129772,"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","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":["component-architecture","dependency-injection","di-container","dsl","ioc","ioc-container","ios","objective-c","swift"],"created_at":"2024-11-13T13:48:05.144Z","updated_at":"2025-04-12T15:36:02.887Z","avatar_url":"https://github.com/baidu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo Banner Light](./Images/logo_banner.svg#gh-light-mode-only)\n![Logo Banner Dark](./Images/logo_banner~dark.svg#gh-dark-mode-only)\n\n![Github Workflow](https://img.shields.io/github/actions/workflow/status/baidu/CarbonGraph/.github/workflows/build.yml?branch=main\u0026style=flat-square)\u0026nbsp;\n![Swift Version](https://img.shields.io/badge/Swift-5.5-orange?style=flat-square)\u0026nbsp;\n![CocoaPods Version](https://img.shields.io/cocoapods/v/CarbonCore?style=flat-square)\u0026nbsp;\n![Platforms](https://img.shields.io/cocoapods/p/CarbonCore?style=flat-square)\u0026nbsp;\n![License](https://img.shields.io/cocoapods/l/CarbonCore?style=flat-square)\n\nCarbonGraph is a Swift dependency injection / lookup framework for iOS. You can use it to build loose coupling between modules.\n\nThe CarbonGraph project contains 2 frameworks:\n\n| Framework | Description |\n| --- | --- |\n| CarbonCore | Focused specifically on core DI implementations |\n| CarbonObjC | CarbonCore's ObjC adaptation framework |\n\n## Features\n\n- [x] Complete dependency injection capabilities\n- [x] Complete Objective-C support\n- [x] Convenient object definition DSL\n- [x] High-performance thread-safe solution\n- [x] Support resolving native Swift types\n- [x] Support resolving with external parameters\n- [x] Support resolving with circular dependencies\n- [x] Automatic scanning of configuration\n- [x] Additional module life cycle management capabilities\n\n## Requirements\n\n* CarbonCore Requirements\n\n| CarbonCore Stable Version | Required iOS Version | Required Swift Version |\n| --- | --- | --- |\n| 1.2.2 - 1.3.2 | 9.0 + | 5.2 + |\n| 1.3.3 | 9.0 + | 5.5 + |\n\n* CarbonObjC Version Compatibility\n\n| CarbonObjC Version | CarbonCore Compatible Version |\n| --- | --- |\n| 1.2.2 | 1.2.2 |\n| 1.3.1 | 1.3.1 - 1.3.3 |\n\nFor more information see [Compatibility](./CarbonCore/CarbonCore/CarbonCore.docc/Compatibility.md)\n\n## Installation\n\nCocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CarbonGraph into your Xcode project using CocoaPods, specify it in your Podfile:\n\n\u003e pod 'CarbonCore', '~\u003e 1.3.3'\n\n## Quick Start\n\n* Basic object registration and resolving\n```swift\nlet context = ObjectContext()\nlet definitionBuilder = Definition(\"filevc\")\n    .protocol(UIViewController.self)\n    .object(FileViewController())\ncontext.register(builder: definitionBuilder)\ncontext[UIViewController.self, name: \"filevc\"]\n```\n\n```swift\nlet context = ObjectContext()\nlet definitionBuilder = Definition()\n    .object(FileManager() as FileManagerProtocol)\ncontext.register(builder: definitionBuilder)\ncontext[FileManagerProtocol.self]\n```\n\n* Use configuration batch registration\n```swift\nclass MyConfiguration: Configuration {\n    static func definitions(of context: ObjectContext) -\u003e Definitions {\n        Definition()\n            .object(FilePath())\n        Definition()\n            .constructor(FileModel.init(filePath:))\n    }\n}\n\nlet context = ObjectContext()\ncontext.register(configuration: MyConfiguration.self)\ncontext[FileModel.self]\n```\n\n## Basic usage\n\n\u003e Note: For convenience, the registration of object definitions and the creation of context that appear in the following will be omitted. All definitions in your project must be registered before they can be resolved.\n\n* Use constructor for dependency injection\n```swift\nDefinition()\n    .protocol(FileViewControllerProtocol.self)\n    .constructor(FileViewController.init(fileManager:))\ncontext[FileViewControllerProtocol.self].fileManager\n```\n\n* Use property for dependency injection\n```swift\nDefinition()\n    .protocol(FileViewControllerProtocol.self)\n    .object(FileViewController())\n    .property(\\.fileManager)\ncontext[FileViewControllerProtocol.self].fileManager\n```\n\n* Use setter for dependency injection\n```swift\nDefinition()\n    .protocol(FileViewControllerProtocol.self)\n    .object(FileViewController())\n    .setter(FileViewController.setFileManager(fileManager:))\ncontext[FileViewControllerProtocol.self].fileManager\n```\n\n* Use static factory for manual dependency injection\n```swift\nDefinition()\n    .factory(fileViewController(context:))\ncontext[FileViewControllerProtocol.self].fileManager\n\nstatic func fileViewController(context: ObjectContext) -\u003e FileViewControllerProtocol {\n    let fileVC = FileViewController()\n    fileVC.fileManager = context[FileManagerProtocol]\n    return fileVC\n}\n```\nThe same as:\n```swift\nDefinition()\n    .factory { context in \n        let fileVC = FileViewController()\n        fileVC.fileManager = context[FileManagerProtocol]\n        return fileVC as FileViewControllerProtocol\n    }\n```\n\n* Create objects with external parameters\n```swift\nDefinition()\n    .factory(fileModel(context:path:name:))\ncontext[FileModelProtocol.self, \"/china/beijing\", \"family.png\"]\n\nstatic func fileModel(context: ObjectContext, path: String, name: String) -\u003e FileModelProtocol {\n    FileModel(path: path, name: name)\n}\n```\n\nFor more information see [Basic usage](./CarbonCore/CarbonCore/CarbonCore.docc/BasicUsage.md)\n\n## Documentation\n\nThe documentation of this project is written in [DocC](https://developer.apple.com/documentation/docc), please clone the repo and build the documentation yourself.\n\n1. Clone this repo \n2. Open Carbon.xcworkspace with Xcode\n3. Product \u003e Build Documentation\n\nFor more information see Unit Test and Example\n\n## Contribution\n\nYou are more than welcome to contribute code to the project，for more information see [Contribution](./CarbonCore/CarbonCore/CarbonCore.docc/Contribution.md). You can also join the WeChat discussion group, check the QR code below.\n\n\u003ca href=\"https://weixin.qq.com/g/AQYAAMrdukzdvyo_JJrKIVjcJXhKFS2Of8v1P6K3bQIIwZ28E1BWAcsfbGWFKEHs\"\u003e\u003cimg width=\"360\" src=\"CarbonCore/CarbonCore/CarbonCore.docc/Resources/wechat_qr_code.jpg\"\u003e\u003c/a\u003e\u0026nbsp;\n\n## License\n\nCarbonGraph is released under the MIT license. See [LICENSE](./LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fcarbongraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaidu%2Fcarbongraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fcarbongraph/lists"}