Fork me on GitHub

Loading Modules

GSPI allows loading com.google.inject.Modules from the SPI in an easy way: define first which Modules you intend to load in the META-INF/services/com.google.inject.Module file(s):

# created by Jack Bauer in less than 24h

com.acme.FooModule
com.acme.BarModule
com.acme.FooTestCase$AcmeModule   # EOL comment

# comments and blank lines supported


#

then, load modules invoking org.nnsoft.guice.gspi.GuiceServiceLoader.* APIs:

import static org.nnsoft.guice.gspi.GuiceServiceLoader.loadModules;
import static com.google.inject.Guice.createInjector;

import com.google.inject.Injector;

...

Injector injector = createInjector( loadModules() );

Eh?!? Just that?!? YES!!! :)

Loading modules from SystemProperties

Alternatively, SPIs can be specified via Java System properties:

java -Dcom.google.inject.Module=com.acme.FooModule,com.acme.BarModule,com.acme.FooTestCase$AcmeModule

Where , is the separator character between Providers.

Note

If SPIs will be found in Java System properties, META-INF/services/com.google.inject.Module file(s) will be ignored