Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency Injection framework for C++ [closed]

Is there a DI framework comparable to Google Guice? And what does Google use?

like image 498
helpermethod Avatar asked Dec 17 '10 09:12

helpermethod


People also ask

Which framework is used for dependency injection?

Spring.NET is one of the popular open source frameworks for Dependency Injection. Spring.NET supports . NET 4.0, . NET Client Profile 3.5 and 4.0, Silverlight 4.0 and 5.0, and Windows Phone 7.0 and 7.1.

What is dependency injection with Example C?

Using dependency injection, we can pass an instance of class C to class B, and pass an instance of B to class A, instead of having these classes to construct the instances of B and C. In the example, below, class Runner has a dependency on the class Logger.

When should I use IServiceProvider?

The IServiceProvider is responsible for resolving instances of types at runtime, as required by the application. These instances can be injected into other services resolved from the same dependency injection container. The ServiceProvider ensures that resolved services live for the expected lifetime.


2 Answers

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.

like image 116
Adrian Petrescu Avatar answered Sep 23 '22 00:09

Adrian Petrescu


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.

like image 23
Daniele Pallastrelli Avatar answered Sep 27 '22 00:09

Daniele Pallastrelli