Interface GuiceyBundle
-
- All Known Implementing Classes:
CoreInstallersBundle
,HK2DebugBundle
,UniqueGuiceyBundle
,WebInstallersBundle
public interface GuiceyBundle
Guicey bundle is an enhancement of dropwizard bundles (ConfiguredBundle
). It allows everything that dropwizard bundles can plus guicey specific features and so assumed to be used instead of dropwizard bundles. But it does not mean that other dropwizard bundles can't be used: both bundle types share the same lifecycle, so you can register dropwizard bundles from within guicey bundle (which is very important for existing bundles re-using).Like dropwizard bundles, guicey bundles contains two lifecycle phases:
- initialization - when all bundles (dropwizard and guicey) must be configured
- run - when dropwizard configuration and environment become available and some additional guicey configurations may be performed
Extensions and guice modules may be registered (or disabled) in both phases (because guice is not yet started for both), but installers are registered only in initialization phase because they are used during classpath scan, performed on dropwizard initialization.
Bundles are extremely useful when autoscan is not used in order to group required extensions installation.
Bundle should be registered into
GuiceBundle
builder.Bundles could be installed automatically with bundle lookups mechanism
GuiceyBundleLookup
. For example, it could be service loader based lookup which automatically installs bundle when it appears in classpath.Multiple instances of the same bundle could be registered (like with dropwizard bundles). But guicey duplicates mechanism will consider equal bundles as duplicate (and register only one). So in order to grant bundle uniqueness simply properly implement equals method or use
UniqueGuiceyBundle
. SeeGuiceBundle.Builder.duplicateConfigDetector( ru.vyarus.dropwizard.guice.module.context.unique.DuplicateConfigDetector)
for duplicates detection mechanism info.- Since:
- 01.08.2015
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default void
initialize(GuiceyBootstrap bootstrap)
Called in initialization phase.default void
run(GuiceyEnvironment environment)
Called on run phase.
-
-
-
Method Detail
-
initialize
default void initialize(GuiceyBootstrap bootstrap)
Called in initialization phase.GuiceyBootstrap
contains almost the same methods asGuiceBundle.Builder
, which allows to register installers, extensions and guice modules. Existing installer could be replaced by disabling old one and registering new.Dropwizard bundles could be also registered with
GuiceyBootstrap.dropwizardBundles(io.dropwizard.ConfiguredBundle[])
shortcut (or by directly accessing dropwizard bootstrap object:GuiceyBootstrap.bootstrap()
.As bundles could be registered only during initialization phase, it is not possible to avoid bundle registration based on configuration (not a good practice). But, it is possible to use guicey options instead: for example, map option from environment variable and use to to decide if some bundles should be activated.
Guicey lifecycle listeners (
GuiceyLifecycleListener
could be registered only on initialization phase (GuiceyBootstrap.listen(ru.vyarus.dropwizard.guice.module.lifecycle.GuiceyLifecycleListener...)
).- Parameters:
bootstrap
- guicey bootstrap object
-
run
default void run(GuiceyEnvironment environment) throws java.lang.Exception
Called on run phase.GuiceyEnvironment
contains almost the same methods asGuiceBundle.Builder
, which allows to register extensions and guice modules.Direct jersey specific registrations are possible through shortcuts
GuiceyEnvironment.register(Object...)
andGuiceyEnvironment.register(Class[])
. Complete dropwizard environment object is accessible withGuiceyEnvironment.environment()
(assumed that it would not be directly required in most cases).Dropwizard configuration is accessible directly with
GuiceyEnvironment.configuration()
and with advanced methodsGuiceyEnvironment.configuration(Class)
,GuiceyEnvironment.configuration(String)
,GuiceyEnvironment.configurations(Class)
andGuiceyEnvironment.configurationTree()
.- Parameters:
environment
- guicey environment object- Throws:
java.lang.Exception
- if something goes wrong
-
-