Guicey lifecycle¶
Tip
Guicey broadcast events in all major points. You can see most of them with enabled lifecycle report.
Configuration phase¶
Note
All manual registrations must be performed under this phase (the only exception is guice modules). All bundles are registered and initialized only under configuration phase.
Everything below happens under bundle registration call:
@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
bootstrap.addBundle(GuiceBundle.builder()
...
.build());
// everything here will be called after all steps below
}
- Main bundle configuration
- Apply configuration hooks
- All option values set and can't be modified anymore.
- Apply registered dropwizard bundles (init delayed to count dropwizard bundle disables).
- Perform classpath scan (if configured). Scan resolve all classes in configured packages to use them later for detection.
- Perform bundles lookup
- Initialize bundles
- Search for commands (if classpath scan enabled)
- Prepare installers:
- Detect installers with classpath scan (if configured)
- Instantiate not disabled installers
- Resolve extensions:
- Validate all enabled manually registered extensions: one of prepared installers must recognize extension or error will be thrown.
- Recognize extensions from classpath scan classes (if configured)
Run phase¶
- Run bundles
- Guice modules may be registered here
- Extensions may still be disabled
- Autowire modules
- Analyze enabled modules
- Detect extensions from bindings
- Remove disabled modules and disabled extensions
- Re-package modules (to avoid duplicate modules parsing by guice)
- Register
GuiceBootsrapModule
- Apply overriding modules
- Create injector (with injector factory)
GuiceBootsrapModule
configures:- Additional bindings (like environment, configuration and jersey-objects)
- Performs extensions registration (either default binding or specific,
performed by
BindingInstaller
) - Register
GuiceFeature
(jerseyFeature
), which will perform jersey initialization - Activate guice ServletModule support
- Since that moment injector could be referenced statically
- Install extensions (except jersey extensions)
- Inject commands
Note
As dropwizard bundles were registered under GuiceBundle
configuration, they will be run by dropwizard
after GuiceBundle
.
Note
Your Application.run()
method will be called after guicey startup, so you can use created
injector there.
Jersey startup¶
Note
Jersey startup will initiate hk2 context creation
- Managed beans started
- hk2 context creation activates
GuiceFeature
(registered earlier)- Apply guice bridge (if required)
- Run jersey specific installers (resource, extension): installers will register required bindings in hk2 context
Note
Any EnvironmentCommand
did no start jersey, so managed objects will not be started (but you can start required
services manually). Also, all jersey related extensions will not be started.
Still, core guice context will be completely operable.
When guice context is created, jersey context doesn't exist and when jersey context is created it doesn't aware of guice existence.