public class GuiceTweaker extends Object implements SpincastPlugin
This allows the tweaking of the Guice context of an application without touching its bootstrapping code.
The first use case for this is to be able to mock some parts of an application in order to test it.
It is the responsibility of the code creating the GuiceTweaker to make sure the ThreadLocal variable is removed.
| Modifier and Type | Field and Description |
|---|---|
static String |
PLUGIN_ID |
static ThreadLocal<GuiceTweaker> |
threadLocal |
| Constructor and Description |
|---|
GuiceTweaker() |
| Modifier and Type | Method and Description |
|---|---|
com.google.inject.Module |
apply(com.google.inject.Module currentModule)
Applies the plugin.
|
void |
bindCurrentClassByDefault(boolean bindCurrentClassByDefault) |
void |
createdGuiceInjector(com.google.inject.Injector injector)
Once all the plugins have been applied,
this method is called with the resulting
Guice injector.
|
protected List<SpincastPlugin> |
getExtraPlugins() |
String |
getId()
The id of the plugin.
|
com.google.inject.Injector |
getInjector() |
protected Set<com.google.inject.Module> |
getModules() |
Set<String> |
getPluginsToDisable()
If required, the ids of plugins that shouldn't
be installed.
|
boolean |
isBindCurrentClassByDefault() |
void |
module(com.google.inject.Module module) |
void |
plugin(SpincastPlugin plugin) |
void |
pluginToDisable(String pluginId) |
void |
setRequestContextImplementationClass(Class<? extends RequestContext<?>> requestContextImplementationClass)
The implementation class to use for RequestContext.
|
void |
setWebsocketContextImplementationClass(Class<? extends WebsocketContext<?>> websocketContextImplementationClass)
The implementation class to use for WebsocletContext.
|
public static final ThreadLocal<GuiceTweaker> threadLocal
public static final String PLUGIN_ID
public String getId()
SpincastPlugingetId in interface SpincastPluginprotected List<SpincastPlugin> getExtraPlugins()
protected Set<com.google.inject.Module> getModules()
public boolean isBindCurrentClassByDefault()
public void createdGuiceInjector(com.google.inject.Injector injector)
SpincastPlugincreatedGuiceInjector in interface SpincastPluginpublic com.google.inject.Injector getInjector()
public com.google.inject.Module apply(com.google.inject.Module currentModule)
SpincastPluginThe plugin can add bindings to the current Guice module, can modify it and can inspect it in order to decide what to bind or not.
apply in interface SpincastPluginpublic Set<String> getPluginsToDisable()
SpincastPluginThis plugin is repsonsible to bind any components that won't be bound because it mark some plugins as to be ignored.
getPluginsToDisable in interface SpincastPluginpublic void setRequestContextImplementationClass(Class<? extends RequestContext<?>> requestContextImplementationClass)
SpincastPluginsetRequestContextImplementationClass in interface SpincastContextTypesInterestedsetRequestContextImplementationClass in interface SpincastPluginpublic void setWebsocketContextImplementationClass(Class<? extends WebsocketContext<?>> websocketContextImplementationClass)
SpincastPluginsetWebsocketContextImplementationClass in interface SpincastContextTypesInterestedsetWebsocketContextImplementationClass in interface SpincastPluginpublic void module(com.google.inject.Module module)
public void plugin(SpincastPlugin plugin)
public void bindCurrentClassByDefault(boolean bindCurrentClassByDefault)
public void pluginToDisable(String pluginId)
Copyright © 2017. All rights reserved.