Skip to main content

Guice Dependency Injection

The Guice module allows Gestalt to inject configuration directly into your classes using Guice and the @InjectConfig annotation on any class fields. This does not support constructor injection due to Guice limitations. To enable this, add the new GestaltModule(gestalt) to your Guice Modules, then pass in your instance of Gestalt.

See the unit tests for examples of use.

Injector injector = Guice.createInjector(new GestaltModule(gestalt));

MyService service = injector.getInstance(MyService.class);

// use the InjectConfig along with the path to inject configuration.
public static class MyService {
@InjectConfig(path = "db.user") DBConnection connection;

public DBConnection getConnection() {
return connection;
}
}