Class GuiceBundle
- All Implemented Interfaces:
io.dropwizard.core.ConfiguredBundle<io.dropwizard.core.Configuration>
ConfigurationAwareModule).
You can use auto scan to automatically install features. To enable auto scan you must configure package (or
packages) to search in. To know all supported features look
FeatureInstaller implementations. Installers are
extendable mechanism: they are resolved by scanning classpath, so you can add new installers in your code and
classpath scanning will find them and activate. Also, installers could be disabled (for example, if you want to
replace existing installer, you will disable it in builder and implement your own - auto scan will find it and
activate).
Any class may be hidden from auto scanning with @InvisibleForScanner annotation.
Commands may use injection too, but only fields injection. You can register command manually and their fields will be injected or you can activate auto scan for commands in builder (disabled by default). If auto scan for commands enabled, they will be instantiated with default no-arg constructor.
Resources are registered using jersey integration module. GuiceFilter is registered for both contexts to provide request and session scopes support.
Lifecycle:
- Bundle configured
- Bundle initialization started
- If commands scan enabled, commands resolved from classpath and registered in Bootstrap
- Bundle run started
- If auto scan enabled, scan classpath for feature installers and perform one more scan with registered installers to find extensions
- Perform
GuiceyBundlelookup with registeredGuiceyBundleLookup - Guice injector created
- Register all extensions found by installers
- Perform injections for all registered environment commands (because only environment commands runs bundles)
Project was originally inspired by dropwizard-guice project. And because of this, project name was changed to dropwizard-guicey.
- Since:
- 31.08.2014
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder encapsulates bundle configuration options. -
Method Summary
Modifier and TypeMethodDescriptionstatic GuiceBundle.Builderbuilder()com.google.inject.InjectorNote that injector could be accessed statically anywhere withInjectorLookup.getInjector(io.dropwizard.core.Application).voidinitialize(io.dropwizard.core.setup.Bootstrap bootstrap) voidrun(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment)
-
Method Details
-
initialize
public void initialize(io.dropwizard.core.setup.Bootstrap bootstrap) - Specified by:
initializein interfaceio.dropwizard.core.ConfiguredBundle<io.dropwizard.core.Configuration>
-
run
public void run(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment) throws Exception - Specified by:
runin interfaceio.dropwizard.core.ConfiguredBundle<io.dropwizard.core.Configuration>- Throws:
Exception
-
getInjector
public com.google.inject.Injector getInjector()Note that injector could be accessed statically anywhere withInjectorLookup.getInjector(io.dropwizard.core.Application).- Returns:
- created injector instance or fail if injector not yet created
- Throws:
IllegalStateException- if injector is not yet created
-
builder
- Returns:
- builder instance to construct bundle
-