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,
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,
but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph
is materialized and injected, meaning that objects are not actually instantiated in dependency order.
Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object
graph has already been instantiated, meaning that objects will be created in dependency order and this will
only actually instantiate something that wasn't actually depended upon.clazz - the class to instantiatepublic 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,
but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph
is materialized and injected, meaning that objects are not actually instantiated in dependency order.
Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object
graph has already been instantiated, meaning that objects will be created in dependency order and this will
only actually instantiate something that wasn't actually dependend upon.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)
Keys 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,
but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph
is materialized and injected, meaning that objects are not actually instantiated in dependency order.
Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object
graph has already been instantiated, meaning that objects will be created in dependency order and this will
only actually instantiate something that wasn't actually dependend upon.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–2023 The Apache Software Foundation. All rights reserved.