Apache Commons Inject is an implementation of JSR 330: Dependency Injection for Java. In other words: It is yet another implementation of JSR 330, much like Guice, Spring, Dagger, and some minor others.

Commons Inject mimicks Guice in most aspects. (For example, if you know the Guice API, you will immediately understand the API of Commons Inject.) However, compared to Guice, you will hopefully note the following differences:

  • Commons Inject is self contained. You don't need Guava, or similar helper jar files.
  • Commons Inject is somewhat easier to use. In particular, you don't need to bother so much about Generics. OTOH, there's no automatic distinction between
      @Inject private List someList;
      @Inject private List<Foo> fooList;

    However, that distinction isn't part of JSR 330, anyways. Instead it is suggested that you use the concept of names:

      @Inject private List someList;
      @Inject @Named(value="foo") private List<Foo> fooList;
  • Commons Inject is based on the standard Java reflection API only. As a consequence, it should work on Android. * Commons Inject doesn't distinguish between production mode, and development mode. OTOH, its startup time should be much faster than Guice in production mode. * Commons Inject provides some extensions out of the box: * Support for an Application Lifecycle, including support for @PostConstruct, and @PreDestroy. This lifecycle support works with arbitrary objects, including eager, or lazy singletons. * Logger injection via Log4J, SLF4J, or Commons Logging. (Adding support for other frameworks should be extremely easy.)