百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

python-inject

> 编程语言
开源

Python 依赖注入

773 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Python 依赖注入

Python-inject() (https://github.com/ivankorobkov/python-inject/actions/workflows/tests.yaml) 依赖注入 Python 方式,这是一个好方法。

也可以使用显式的括号表示法(@inject.autoparams())来绑定非参数化的装饰器 - 它将被处理与 @inject.autoparams() 相同。

python
import inject
inject.configure(my_config, once=True)

测试

在测试中,请使用 inject.configure(callable, clear=True) 在设置时创建新的注入器, 以及可选的 inject.clear() 以在卸载时清理:

python
class MyTest(unittest.TestCase):
    def setUp(self):
        inject.configure(lambda binder: binder
            .bind(Cache, MockCache()) \
            .bind(Validator, TestValidator()),
            clear=True)
    
    def tearDown(self):
        inject.clear()

可组合的配置

您可以重新使用配置和过滤器

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言