C++ 的依赖注入框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4469304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dependency Injection framework for C++
提问by helpermethod
Is there a DI framework comparable to Google Guice? And what does Google use?
是否有可与 Google Guice 相媲美的 DI 框架?谷歌使用什么?
采纳答案by Adrian Petrescu
There is nothing as mature or standard as Guice in the C++ world. However, some people have put together simplistic implementations on their own. Here's a couple.
在 C++ 世界中,没有像 Guice 那样成熟或标准的东西。但是,有些人自己将简单的实现组合在一起。这是一对。
- http://adam.younglogic.com/2008/07/dependency-injection-in-c/(source for implementation is at the end of the post)
- http://sourceforge.net/projects/qtioccontainer/(requires Qt)
- http://code.google.com/p/autumnframework/(hasn't been touched since 2007)
- http://programmaticallyspeaking.blogspot.com/2010/04/beautiful-dependency-injection-in-c.html(more of a description, really)
- http://sourceforge.net/projects/cpp-resolver/("Alpha" quality)
- http://adam.younglogic.com/2008/07/dependency-injection-in-c/(实现来源在帖子末尾)
- http://sourceforge.net/projects/qtioccontainer/(需要 Qt)
- http://code.google.com/p/autumnframework/(自 2007 年以来没有被触及)
- http://programmaticallyspeaking.blogspot.com/2010/04/beautiful-dependency-injection-in-c.html(更多的是描述,真的)
- http://sourceforge.net/projects/cpp-resolver/(“Alpha”质量)
You're unlikely to be satisfied by any of these.
您不太可能对其中任何一个感到满意。
If you really wanted to put in the effort to rally the world around a DI framework for C++, probably the way to go about it would be to make a proposal to the Boost guys.
如果你真的想努力让世界围绕 C++ 的 DI 框架团结起来,那么可能的方法是向 Boost 人员提出建议。
回答by Daniele Pallastrelli
I'm the author of wallaroo. It's actively developed and has the following features:
我是wallaroo的作者。它正在积极开发并具有以下特点:
- it's lightweight but powerful
- its interface supports both C++11 and C++98 with boost
- it's type safe
- it doesn't need custom preprocessors / code generators
- you can load classes defined in shared libraries
- you can use a DSL syntax for object creation and wiring or
- you can get object creation and wiring by parsing one or more xml / json file.
- 它轻巧但功能强大
- 它的接口支持 C++11 和 C++98 与 boost
- 它是类型安全的
- 它不需要自定义预处理器/代码生成器
- 您可以加载共享库中定义的类
- 您可以使用 DSL 语法来创建和连接对象,或者
- 您可以通过解析一个或多个 xml / json 文件来获得对象的创建和连接。
Any comment, suggestion or request are welcome.
欢迎任何意见、建议或要求。
回答by lurscher
There is a recent one that looks very interesting called Hypodermic, i haven't tested it but it looks pretty active
最近有一个看起来很有趣的叫做Hypodermic,我没有测试过,但它看起来很活跃