Class GuiceyRunner
java.lang.Object
ru.vyarus.dropwizard.guice.module.GuiceyRunner
Guicey run logic performed under dropwizard run phase.
- Since:
- 05.08.2019
-
Constructor Summary
ConstructorsConstructorDescriptionGuiceyRunner(ConfigurationContext context, io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment) Create runner. -
Method Summary
Modifier and TypeMethodDescriptionIterable<com.google.inject.Module>If configuration from guice bindings is enabled, configured guice modules will be repackaged in order to resolve all configured bindings (and filter disabled bindings to simulate common extensions disable behaviour).voidcreateInjector(InjectorFactory injectorFactory, Iterable<com.google.inject.Module> modules) voidInject application fields (to use in run method).voidInject fields in registered commands.voidExecute extensions installation (by type and instance).voidPrepare guice modules for injector creation.voidExtensions could be registered in run phase too.voidProcess run phase for guicey bundles.voidRun lifecycle end.
-
Constructor Details
-
GuiceyRunner
public GuiceyRunner(ConfigurationContext context, io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment) Create runner.- Parameters:
context- configuration contextconfiguration- configurationenvironment- environment
-
-
Method Details
-
runBundles
Process run phase for guicey bundles. Note: dropwizard bundles registered afterGuiceBundle(or within it) will be processed after that point (because they will be registered after guice bundle and so dropwizard will call their run methods after guice bundle's run).- Throws:
Exception- if something goes wrong
-
registerExtensions
public void registerExtensions()Extensions could be registered in run phase too. Auto scan was performed under configuration phase, but without registration (only recognition) - now register all extensions. -
prepareModules
public void prepareModules()Prepare guice modules for injector creation. -
analyzeAndRepackageBindings
If configuration from guice bindings is enabled, configured guice modules will be repackaged in order to resolve all configured bindings (and filter disabled bindings to simulate common extensions disable behaviour).Note that analysis step use guice elements SPI, which guice will use in any case. And to avoid duplicate work on injector creation, analyzed elements are packaged into synthetic guice module and passed to injector instead of original modules.
After bindings analysis all extensions are finally registered and entire configuration info is finalized.
When bindings configuration is disabled (with
GuiceyOptions.AnalyzeGuiceModules), no modules repackaging is applied (exact legacy guicey behavior). It may also be useful to disable feature to check for side effects.- Returns:
- modules to use
-
createInjector
public void createInjector(InjectorFactory injectorFactory, Iterable<com.google.inject.Module> modules) - Parameters:
injectorFactory- configured injector factorymodules- guice modules to use for injector
-
installExtensions
public void installExtensions()Execute extensions installation (by type and instance). -
injectApplication
public void injectApplication()Inject application fields (to use in run method). -
injectCommands
public void injectCommands()Inject fields in registered commands. This step is actually required only if currently executed dropwizard command require such injections. -
runFinished
public void runFinished()Run lifecycle end.
-