This is a compilation of common usage doubts, tips and workarounds.

Why IoC Utils?

IoC Utils provides a wrapper for any IoC framework you wish to use. By default it provides the Google Guice implementation, but it can easily be extended to implement any other IoC framework (see for more on this).

This gives the ability to easily switch IoC implementations in projects, abstracting it from the client code IoC framework. IoCUtils might also be used to implement workarounds or extensions to your IoC framework functionality set.

Can IoC Utils add features to the underlying IoC framework?

Yes it can. Workarounds for common needs not natively supported by the IoC framework used can be added to IoCUtils.

One such example is module finding for drop-in JARs. IoC Utils has added this feature to the default Google Guice IoC framework. IoC Utils has also made easy the use of multiple implementations of the same service in Guice, through the use of the implementation annotations and a helper method that compiles all existing implementations is a simple and useful Map of implementations. All of this can be read in the User Guide section.

Why Google Guice as the default implementation?

We chose Google Guice because of it's simple and lightweight implementation. It is one of the fastest IoC framework implementation and has a low memory footprint.

By using IoC utils can I completely shield my code from the underlying IoC framework?

Alas this may not be possible. Depending on the IoC used you may have to:

  • Inject services in other services (may do it using the IoC utils but is normally easier using the chosen IoC framework directly)

These operation must be done directly with the chosen IoC because there is not a standard specification for IoC frameworks. Each one has it's own way of doing things. Currently there are a few JSR in the Java Community Process that may change this. If so, IoC Utils can then proceed to the next level of abstraction of the underlying IoC framework used. Until then this is the small price we still have to pay.

How do I declare a new JAR with a set of services to the IoC framework?

IoC Utils supports the concept of drop-in JARs. To do this we only have to bundle a configuration file "modules.properties" in the JAR with the corresponding classes of the service interfaces, service implementations and service modules. At startup, the IoC Utils will find these modules and pass them to the IoC framework for initialization. No configuration is needed. Just drop the JAR in and restart the Application Server.

Can I override a provided default service implementation with my own without changing the default Module binding?

Yes you can. You can have several modules that define services and have a specific application module override some of these default service implementations. All you have to do is add .override() to your bind declaration. All of this can be read in the User Guide section.

Can I declare a service and prevent developers to override it?

Yes you can. Declare it with .asFinal(). All of this can be read in the User Guide section.