1

I've been working on a writing a game for Android. Until now I've been using Java instead of the NDK, but I've decided to port my code to C++ (for performance, memory management and industry standards reasons).

Porting my application shouldn't be a problem (I've written my fair share of C++ applications), but I've been using RoboGuice as a dependency injection framework because otherwise my object graph would become too complex rather quickly. I've been looking around, but I haven't found any resources about using a dependency injection framework in combination with the Android NDK.

Can someone tell me if there any such franeworks available. If so, which one would you recommend?

ChrisV
  • 133
  • 2
  • 9

1 Answers1

0

If you have a C++11 compiler for Android you could use several frameworks (I wrote Infectorpp) but there are others available. You should note that DI is quite limited in C++ due to the lack of reflection so you should make some compromises as not everything you did in RoboGuice would still be possible.

By doing a quick search seems that C++11 is possible on Android. I don't have an Android device and still not needed to emulate it, but if you have any feedback it will be wellcome (private message here or support ticket on google code is enough), the library is headers only so no special build stuff is required for it, apart enabling c++11 on your compiler wich is just one extra option by command line. If that will works good on Android then it will be definitely good also for PC. (Do not misunderstand please, I'm using it heavily, but seems very few people is interested in DI in C++ and so I get very little feedback)

There was also a nice framework cpp-resolver: a little awkard to use because you explicitly register factory functions for injecting ALL parameters, but very scalable, especially for server applications.. (decouple object lifetime management and works with plain old C++).

The most complete framework is probably wallaroo

  1. If you search something really easy to use Infectorpp is a good choice
  2. If you need control over lifetime (mostly servers): Cpp-resolver is perfect
  3. If you need exotic features and configuration files: wallaroo

As side note, run-time configuration is possible also with frameworks that do not explicitly support it:

You just need a Factory that istantiate a different type based on a configuration file you could read through a class that you add as dependency to factories (Probably you don't need to know that since you were already using DI frameworks, but still good to know for occasional readers)

Community
  • 1
  • 1
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69
  • I'm the author of wallaroo: the library is NOT limited to 2 dependencies only! You can have as many dependencies as you need. Indeed, you can also add an unlimited number of attributes. – Daniele Pallastrelli Mar 23 '15 at 13:03
  • https://code.google.com/p/wallaroo/wiki/CtorParameters so it was updated? hack solutions are not solutions. compile time framworks provide the general solution with least runtime overhead. Of course depend on initial architectural choice, dynamic resolution vs static resolution is such a choice. – CoffeDeveloper Mar 24 '15 at 15:00
  • Ctor parameters are one thing, dependencies are another. Please read the docs before giving wrong information. – Daniele Pallastrelli Mar 24 '15 at 22:30
  • Compile time frameworks provide the general solution... unless you need runtime configuration from files! – Daniele Pallastrelli Mar 24 '15 at 22:31