Why write a Guice-lib for Android

Posted: November 17, 2009 in Android, Java, Mobile
Tags: ,

As background, yes I do have some Java enterprise coding chops where I am quite use to using IoC frameworks such as Spring. In which case you not only use Spring to make better MVC boundary definitions but also to write better unit tests via mocks etc.

Unlike Spring IoC on Android one has to use a non aop IoC such as Guice no aop library. What is missing is the Guice Modules specific to android. I could use Guice-Robo but there is not really light-weight. Not that there is anythign wrong as obviously you could load the Guice injector at the splash screen and thus avoid some of the initialization of a heavier IoC framework time by hiding that via having the user see the application splash screen.

And since we cannot use AOP anyway why mess with over-riding a class-loader? I could hand-roll my own Dependency Injection such as Bison2 does. It would at least be light enough that I could start to be able to churn out android libraries that are somewhat more flexible.

Plus, writing a dependency injection framework for Android might even be loads of fun.

Reblog this post [with Zemanta]
  1. Mike says:

    Hi Fred, you’re absolutely right, I’ve been using a splash page to initialize the dependency injection framework in the background in my own applications. I’ve got a bug open to provide a general template for this to make it easier for other users to do the same. If you want to keep an eye on it you can see it here: http://code.google.com/p/robo-guice/issues/detail?id=14

  2. Piwaï says:

    Maybe you didn’t try robo-guice hard enough 🙂 . It is quite customizable, and actually isn’t that heavy.

    Of course one might not use it for high performance 3D apps… but the advantages of using an IoC framework outnumbers the few more instances created by Guice.

    Not to say that it brings some killer feature such as @InjectResource(R.string.app_name) and @InjectExtra(“myExtra”) annotations… And a Context scope 🙂 .

    The only thing that might refrain you from using it is that it is currently not in a stable 1.0 release… and the API is still subject to change. But we are getting close to it!

  3. Just wanted to add that there’s another lightweight DI for android that predates bison2’s, it’s part of the skylight1 project: http://code.google.com/p/skylight1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s