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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:28:56  来源:igfitidea点击:

Dependency Injection framework for C++

c++dependency-injection

提问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 那样成熟或标准的东西。但是,有些人自己将简单的实现组合在一起。这是一对。

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,我没有测试过,但它看起来很活跃

回答by phs

I am currently authoring one called sauce, whose design (and name) is directly inspired by guice. I still consider it alpha, but you may find it useful.

我目前正在创作一个名为sauce,其设计(和名称)直接受 guice 启发。我仍然认为它是 alpha,但你可能会发现它很有用。