CarbonGraph is a Swift dependency injection / lookup framework for iOS. You can use it to build loose coupling between modules.
The CarbonGraph project contains 2 frameworks:
Framework | Description |
---|---|
CarbonCore | Focused specifically on core DI implementations |
CarbonObjC | CarbonCore's ObjC adaptation framework |
CarbonCore Stable Version | Required iOS Version | Required Swift Version |
---|---|---|
1.2.2, 1.3.1 | 9.0 | 5.2 |
CarbonObjC Version | CarbonCore Compatible Version |
---|---|
1.2.2 | 1.2.2 |
1.3.1 | 1.3.1 |
For more information see Compatibility
CocoaPods 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:
pod 'CarbonCore', '~> 1.3.1'
let context = ObjectContext()
let definitionBuilder = Definition("filevc")
.protocol(UIViewController.self)
.object(FileViewController())
context.register(builder: definitionBuilder)
context[UIViewController.self, name: "filevc"]
let context = ObjectContext()
let definitionBuilder = Definition()
.object(FileManager() as FileManagerProtocol)
context.register(builder: definitionBuilder)
context[FileManagerProtocol.self]
class MyConfiguration: Configuration {
static func definitions(of context: ObjectContext) -> Definitions {
Definition()
.object(FilePath())
Definition()
.constructor(FileModel.init(filePath:))
}
}
let context = ObjectContext()
context.register(configuration: MyConfiguration.self)
context[FileModel.self]
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.
Definition()
.protocol(FileViewControllerProtocol.self)
.constructor(FileViewController.init(fileManager:))
context[FileViewControllerProtocol.self].fileManager
Definition()
.protocol(FileViewControllerProtocol.self)
.object(FileViewController())
.property(\.fileManager)
context[FileViewControllerProtocol.self].fileManager
Definition()
.protocol(FileViewControllerProtocol.self)
.object(FileViewController())
.setter(FileViewController.setFileManager(fileManager:))
context[FileViewControllerProtocol.self].fileManager
Definition()
.factory(fileViewController(context:))
context[FileViewControllerProtocol.self].fileManager
static func fileViewController(context: ObjectContext) -> FileViewControllerProtocol {
let fileVC = FileViewController()
fileVC.fileManager = context[FileManagerProtocol]
return fileVC
}
The same as:
Definition()
.factory { context in
let fileVC = FileViewController()
fileVC.fileManager = context[FileManagerProtocol]
return fileVC as FileViewControllerProtocol
}
Definition()
.factory(fileModel(context:path:name:))
context[FileModelProtocol.self, "/china/beijing", "family.png"]
static func fileModel(context: ObjectContext, path: String, name: String) -> FileModelProtocol {
FileModel(path: path, name: name)
}
For more information see Basic usage
The documentation of this project is written in DocC, please clone the repo and build the documentation yourself.
For more information see Unit Test and Example
You are more than welcome to contribute code to the project,for more information see Contribution. You can also join the WeChat discussion group, check the QR code below.
CarbonGraph is released under the MIT license. See LICENSE for details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型