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

di

> 设计协作
开源

C++14 依赖注入库

1.3K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

C++14 依赖注入库

--------------------------------------- boost-ext.di 仅需一个头文件的 C++14 依赖注入库,无任何依赖 https://www.youtube.com/watch?v=yVogS4NbL6U --- 快速入门 下载 boost-ext.di 只需要一个文件。获取最新的头文件! 编译 GCC/Clang sh $CXX -std=c++14 -O2 -fno-exceptions -fno-rtti -Wall -Werror -pedantic-errors file.cpp MSVC sh cl /std:c++14 /Ox /W3 file.cpp 快速指南 - 创建对象图 cpp 类 ctor { public: explicit ctor(int i) : i(i) {} int i; }; 结构体 aggregate { double d; }; 类 example { public: example(aggregate a, const ctor& c) { assert(87.0 == a.d); assert(42 == c.i); }; }; int main() { const auto injector = di::makeinjector( di::bind.to(42), di::bind.to(87.0) ); injector.create(); } 在 Wandbox 上运行此示例。 Clang-3.8 GCC-6 MSVC-2015 编译时间 0.102s 0.118s 0.296s 二进制大小(去除) 6.2kb 6.2kb 105kb ASM x86-64 xor eax, eax retq 快速指南 - 绑定接口 cpp 结构 interface { virtual interface() noexcept = default; virtual int get() const = 0; }; 类 implementation : public interface { public: int get() const override { return 42; } }; 结构 example { example(std::sharedptr i) { assert(42 == i-get()); } }; int main() { const auto injector = di::makeinjector( di::bind.to() ); injector.create(); } 在 Wandbox 上运行此示例。 Clang-3.8 GCC-6 MSVC-2015 编译时间 0.102s 0.118s 0.296s 二进制大小(去除) 6.2kb 6.2kb 105kb ASM x86-64 (与 makeunique 相同) push %rbx mov %rdi,%rbx mov $0x8,%edi callq 0x4008e0 movq $0x400c78,(%rax) mov %rax,(%rbx) mov %rbx,%rax pop %rbx retq 快速指南 - 绑定模板 … 在 Wandbox 上运行此示例。 Clang-3.8 GCC-6 MSVC-2015 编译时间 0.102s 0.118s 0.296s 二进制大小(去除) 6.2kb 6.2kb 105kb ASM x86-64 xor eax, eax retq 快速指南 - 绑定概念 cpp 结构 Streamable { template auto requires(T&& t) - decltype( int( t.read() ), t.write(int) ); }; 模板类 example { public: example(Exchange exchange, Engine engine) : exchange(std::move(exchange)), engine(std::move(engine)) { } private: Exchange exchange; Engine engine; }; int main() { const auto injector = di::makeinjector(…

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

C++dependency-injectiondesign-patterns

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

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类设计协作
定价开源

> 相关工具

F
Figma
协作式界面设计工具
S
sketch-wakatime
Sketch plugin for automatic time tracking and metrics generated from your Sketch usage.
Q
QuickColor
Quickly apply fills from the global or document color palettes to selected elements - 🎨