登录 注册
其他
2,934
Stars
194
Forks
28
Watchers
1
Open Issues
MIT
许可证
Swift
语言
2022-06-01
创建时间
2026-11-07
最近更新

项目能做什么

面向 Swift 和 SwiftUI 的现代化容器依赖注入(DI)框架。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fhmlongco%2FFactory%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/hmlongco/Factory)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fhmlongco%2FFactory%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/hmlongco/Factory)

![](https://github.com/hmlongco/Factory/blob/main/Logo.png?raw=true)

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

## Factory Version 3.5.3

Factory is strongly influenced by SwiftUI, and in my opinion is highly suited for that environment. Factory is...

- **Adaptable**: Factory doesn't tie you down to a single dependency injection strategy or technique.
- **Powerful**: Factory supports containers, scopes, passed parameters, scenes, contexts, decorators, unit tests, SwiftUI Previews, and much, much more.
- **Performant**: Little to no setup time is needed for the vast majority of your services, resolutions are extremely fast, and no compile-time scripts or build phases are needed.
- **Safe**: Factory is compile-time safe; a factory for a given type must exist or the code simply will not compile.
- **Concise**: Defining a registration usually takes just a single line of code. Same for resolution.
- **Flexible**: Working with UIKIt or SwiftUI? iOS or macOS? Using MVVM? MVP? Clean? VIPER? No problem. Factory works with all of these and more.
- **Documented**: Factory has extensive DocC documentation and examples covering its classes, methods, and use cases.
- **Lightweight**: With all of that Factory is slim and trim, under 1,000 lines of executable code.
- **Tested**: Unit tests with 100% code coverage helps ensure correct operation of registrations, resolutions, and scopes.
- **Testable**: Factory ensures your application's views and services are easily previewable and testable. 
- **Free**: Factory is free and open source under the MIT License.

Sound too good to be true? Let's take a look.

---

## A Simple Factory
 
Most container-based dependency injection systems require you to define in some way that a given service type is available for injection, and many require some sort of factory or mechanism that will provide a new instance of the service when needed.
 
 Factory is no exception. Here's a simple dependency registration that returns a service that conforms to `MyServiceType`.
 
```swift
extension Container {
    var myService: Factory<MyServiceType> { 
        self { MyService() }
    }
}
```

Unlike frameworks that require registering every single type up front, or SwiftUI, where defining a new environment variable requires creating a new EnvironmentKey and adding additional getters and setters, here we simply add a new `Factory` computed variable to the default container. When it's called our Factory is created, its closure is evaluated, and we get an instance of our dependency when we need it. 

*That `self { ... 
阅读完整原文

项目深度分析 AI 生成

SwiftUI 企业级生产力架构模版与样板工程 (Boilerplate)

产品构想基于 Factory 设计一套开箱即用的现代化 SwiftUI 全功能商业 App 模板(集成网络层、认证、本地缓存、多环境Mock、Factory 动态依赖切换),缩短研发冷启动周期。
核心功能深度集成 Factory 的环境分发设计、完整的单元测试与 Preview 驱动方案、CI/CD 自动化工作流预设、多种依赖作用域(Scope)最佳实践样板
目标用户独立开发者、初创团队技术负责人、跨界转入 iOS 的开发者
难度/周期低 · 2 - 3 周 · 成本:极低(主要是模板开发和文档整理的时间成本)
收费模式Gumroad/Lemon Squeezy 一次性买断授权销售($49 - $149)
竞争风险买断制模板市场竞争激烈,需持续适配 iOS/SwiftUI 新版本
依据 AI推测

大型 iOS 工程解耦与模块化企业咨询/培训服务

产品构想针对从中大型单体 iOS 仓库向模块化(SPM/Tuist)演进的企业,提供基于 Factory 的依赖解耦、编译时提速方案与架构咨询培训。
核心功能遗留代码依赖重构方案设计、模块间防循环依赖治理策略、团队内部内训课程、定制化 Factory 扩展代码支持
目标用户中大型科技公司的 iOS 客户端架构师、移动端 Tech Lead
难度/周期中等 · 按项目交付(1 - 4 周) · 成本:低(主要为人力交付成本)
收费模式企业技术顾问费、按人头收取的架构实战培训费
竞争风险B端获客周期长,严重依赖个人技术品牌与人脉积累
依据 尚需验证的假设

Factory 依赖可视化分析与测试 Mock 辅助 Mac 开发工具

产品构想构建一款针对 iOS/macOS 开发者的 macOS 菜单栏或独立诊断工具,静态分析项目中的 Factory 容器注册关系,直观呈现依赖拓扑图并辅助一键生成测试 Mock 桩代码。
核心功能Container 拓扑关系可视化、循环依赖告警、自动基于 Factory 注册表生成 XCTest Mock 代码插件、支持 SwiftUI Previews 动态调试注入
目标用户中高级 iOS 研发工程师、注重测试驱动开发(TDD)的开发者
难度/周期中等 · 1 - 2 个月 · 成本:Apple 开发者账号年费($99)及开发测试机
收费模式Mac App Store 独立付费下载或 Setapp 订阅分成
竞争风险Swift 静态解析复杂度较高,工具链生态易受 Xcode 更新破坏
依据 AI推测
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
hiyouga/LlamaFactory 中文介绍暂未生成
Unified Efficient Fine-Tuning of 100+ LLMs & VLMs (ACL 2024)
76,016 Python
thoughtbot/factory_bot 中文介绍暂未生成
A library for setting up Ruby objects as test data.
8,167 Ruby
YILS-LIN/short-video-factory 中文介绍暂未生成
一键生成产品营销与泛内容短视频,AI批量自动剪辑,高颜值跨平台桌面端工具 One click generation of
6,125 TypeScript
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2022-06-01,近 30 天仍在推送,发布过 77 个 Release
社区活跃Star 2,934 / Fork 194 / Issue 1(数据支持,可自行核实)
许可证MIT
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

此项目未提供 Docker 镜像,安装步骤以原仓库 README 为准(涉及依赖安装与环境配置,对新手门槛较高)。