Skip to content

Getting Started

Kostas Christidis edited this page Mar 27, 2019 · 27 revisions

Quick Start

Governator is mostly transparent. Use Guice as you normally would but with enhanced features. The major difference is that you now create the Injector through Governator.

Injector    injector = LifecycleInjector.builder()
    .withModules(yourModules).build().createInjector();

By creating your Injector this way various special annotations (@PostConstruct, etc.) will be processed.

Just a Bit More

By adding two more lines of code a number of other Governator enhancements are enabled.

LifecycleManager    manager = injector.getInstance(LifecycleManager.class);
manager.start();

Starting the Governator LifecycleManager causes field validation to be processed and the Governator @WarmUp methods to get executed.

When your application is shutting down, stop the LifecycleManager so that @PreDestroy methods are executed.

manager.close();

Auto Binding

While Guice has some support for automatic binding (Just in Time – JIT – binding), its functionality is limited in that the instance has to be injected into some other object so that Guice is aware of it. Governator normalizes automatic binding via classpath scanning and the @AutoBindSingleton and @AutoBind annotations.

See Auto Binding for details.

Next Steps

See these feature specific wikis to learn more detail about the above features or additional features:

Additionally, there are examples of Governator’s features.