public class LifecycleModule extends Object implements com.google.inject.Module
DruidGuiceExtensions
must also be included.Constructor and Description |
---|
LifecycleModule() |
Modifier and Type | Method and Description |
---|---|
void |
configure(com.google.inject.Binder binder) |
Lifecycle |
getLifecycle(com.google.inject.Injector injector) |
static void |
register(com.google.inject.Binder binder,
Class<?> clazz)
Registers a class to instantiate eagerly.
|
static void |
register(com.google.inject.Binder binder,
Class<?> clazz,
Annotation annotation)
Registers a class/annotation combination to instantiate eagerly.
|
static void |
register(com.google.inject.Binder binder,
Class<?> clazz,
Class<? extends Annotation> annotation)
Registers a class/annotation combination to instantiate eagerly.
|
static void |
registerKey(com.google.inject.Binder binder,
com.google.inject.Key<?> key)
Registers a key to instantiate eagerly.
|
public static void register(com.google.inject.Binder binder, Class<?> clazz)
Lifecycle
to be the primary entry point from the injector, not to
auto-register things with the Lifecycle
. It is also possible to just bind things eagerly with Guice,
it is not clear which is actually the best approach. This is more explicit, but eager bindings inside of modules
is less error-prone.clazz,
- the class to instantiatepublic static void register(com.google.inject.Binder binder, Class<?> clazz, Annotation annotation)
Lifecycle
to be the primary entry point from the injector, not to
auto-register things with the Lifecycle
. It is also possible to just bind things eagerly with Guice,
it is not clear which is actually the best approach. This is more explicit, but eager bindings inside of modules
is less error-prone.clazz,
- the class to instantiateannotation
- The annotation instance to register with Guice, usually a Named annotationpublic static void register(com.google.inject.Binder binder, Class<?> clazz, Class<? extends Annotation> annotation)
Lifecycle
to be the primary entry point from the injector, not to
auto-register things with the Lifecycle
. It is also possible to just bind things eagerly with Guice,
it is not clear which is actually the best approach. This is more explicit, but eager bindings inside of modules
is less error-prone.clazz,
- the class to instantiateannotation
- The annotation class to register with Guicepublic static void registerKey(com.google.inject.Binder binder, com.google.inject.Key<?> key)
Key
s mentioned here will be pulled out of
the injector with an injector.getInstance() call when the lifecycle is created.
Eagerly loaded classes will *not* be automatically added to the Lifecycle unless they are bound to the proper
scope. That is, they are generally eagerly loaded because the loading operation will produce some beneficial
side-effect even if nothing actually directly depends on the instance.
This mechanism exists to allow the Lifecycle
to be the primary entry point
from the injector, not to auto-register things with the Lifecycle
. It is
also possible to just bind things eagerly with Guice, it is not clear which is actually the best approach.
This is more explicit, but eager bindings inside of modules is less error-prone.key
- The key to use in finding the DruidNode instancepublic void configure(com.google.inject.Binder binder)
configure
in interface com.google.inject.Module
@Provides public Lifecycle getLifecycle(com.google.inject.Injector injector)
Copyright © 2011–2017. All rights reserved.