Is there a DI framework comparable to Google Guice? And what does Google use?
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.
- 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)
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.
I’m the author of wallaroo. It’s actively developed and has the following features:
- 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.
Any comment, suggestion or request are welcome.
There is a recent one that looks very interesting called Hypodermic, i haven’t tested it but it looks pretty active
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.