Class EagerSingletonInstaller
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.installer.feature.eager.EagerSingletonInstaller
-
- All Implemented Interfaces:
FeatureInstaller
,BindingInstaller
public class EagerSingletonInstaller extends java.lang.Object implements FeatureInstaller, BindingInstaller
Search for classes with@EagerSingleton
annotation and register them in guice context. This may be useful for outstanding classes (not injected by other beans and so not registered with guice. Normally such classes must be manually registered, but using@EagerSingleton
annotation allows to register them automatically. Moreover, even in DEVELOPMENT stage instance will be requested, which makes class suitable for initialization logic.- Since:
- 01.09.2014
-
-
Constructor Summary
Constructors Constructor Description EagerSingletonInstaller()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazy)
Called to apply custom binding for installed feature.void
extensionBound(com.google.inject.Stage stage, java.lang.Class<?> type)
Called after execution of one of above methods.<T> void
manualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)
Called for extensions, resolved from guice bindings (in user modules).boolean
matches(java.lang.Class<?> type)
NOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils
to simplify checks (for example, types most likely must be checks to be not abstract).void
report()
Called to log registered endpoints in dropwizard log fashion.
-
-
-
Method Detail
-
matches
public boolean matches(java.lang.Class<?> type)
Description copied from interface:FeatureInstaller
NOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils
to simplify checks (for example, types most likely must be checks to be not abstract).When type accepted by any extension it's registered in guice module.
- Specified by:
matches
in interfaceFeatureInstaller
- Parameters:
type
- type to check- Returns:
- true if extension recognized, false otherwise
-
bind
public void bind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazy)
Description copied from interface:BindingInstaller
Called to apply custom binding for installed feature. By default, all found extensions are installed asbinder.bind(type)
. This method will be called instead of default registration.Called only for non binding extensions (extensions that are not already bound in guice module.
WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
bind
in interfaceBindingInstaller
- Parameters:
binder
- guice bindertype
- extension classlazy
- true if extension is annotated withLazyBinding
-
manualBinding
public <T> void manualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)
Description copied from interface:BindingInstaller
Called for extensions, resolved from guice bindings (in user modules). May be used to validate binding or do some additional bindings with existing binding. Binding is detected primarily by main keyBinding.getKey()
, but linked bindings (LinkedKeyBinding
) are also checked for target key (LinkedKeyBinding.getLinkedKey()
).LazyBinding
flag is not used here because guicey will automatically throw an error if existing binding is annotated as lazy binding (which don't makes any sense).WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
manualBinding
in interfaceBindingInstaller
- Type Parameters:
T
- extension type, used to connect extension class with binding- Parameters:
binder
- guice bindertype
- extension classbinding
- binding declaration from guice module- See Also:
for errors reporting
-
extensionBound
public void extensionBound(com.google.inject.Stage stage, java.lang.Class<?> type)
Description copied from interface:BindingInstaller
Called after execution of one of above methods. Useful for reporting.Binder
is not provided here to avoid confusion withBindingInstaller.bind(Binder, Class, boolean)
.WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
extensionBound
in interfaceBindingInstaller
- Parameters:
stage
- stage (useful for differentiation between normal run (Stage.PRODUCTION
) and report rendering (Stage.TOOL
)type
- extension class
-
report
public void report()
Description copied from interface:FeatureInstaller
Called to log registered endpoints in dropwizard log fashion. It's important to naturally show all dynamically resolved classes to easily catch errors. UseReporter
to simplify reporting.Method may do nothing if reporting not required
- Specified by:
report
in interfaceFeatureInstaller
-
-