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 |
|---|---|
protected com.google.inject.Module |
addOverridingModules(com.google.inject.Module combinedModule)
Those overriding modules will be added
both *before* and then, again, *after*
the plugins are applied.
|
com.google.inject.Module |
afterPlugins(com.google.inject.Module combinedModule)
Ran after the plugins are applied in
SpincastBootstrapper.
|
com.google.inject.Module |
apply(com.google.inject.Module currentModule)
Ran as a regular plugin.
|
com.google.inject.Module |
beforePlugins(com.google.inject.Module combinedModule)
Ran before the plugins are applied in
SpincastBootstrapper.
|
void |
bindingHierarchyToRemove(Class<?> parentClass)
An binding hierarchy to remove from the combined modules.
|
void |
createdGuiceInjector(com.google.inject.Injector injector)
Once all the plugins have been applied,
this method is called with the resulting
Guice injector.
|
void |
disableBindCurrentClass() |
void |
exactBindingToRemove(com.google.inject.Key<?> key)
An exact binding to remove from the combined modules.
|
Set<Class<?>> |
getBindingsHierarchiesToRemoveBeforePlugins() |
protected Set<com.google.inject.Key<?>> |
getExactBindingsToRemoveBeforePlugins() |
protected List<SpincastPlugin> |
getExtraPlugins() |
String |
getId()
The id of the plugin.
|
com.google.inject.Injector |
getInjector() |
protected Set<com.google.inject.Module> |
getOverridingModules() |
Set<String> |
getPluginsToDisable()
If required, the ids of plugins that shouldn't
be installed.
|
protected Class<? extends RequestContext<?>> |
getRequestContextImplementationClass() |
protected Class<? extends WebsocketContext<?>> |
getWebsocketContextImplementationClass() |
boolean |
isDisableBindCurrentClass() |
void |
overridingModule(com.google.inject.Module overridingModule)
Adds an overriding Module.
|
void |
plugin(SpincastPlugin plugin)
Adds an extra plugin to be applied when
the Guice context is created.
|
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> getOverridingModules()
protected Set<com.google.inject.Key<?>> getExactBindingsToRemoveBeforePlugins()
public Set<Class<?>> getBindingsHierarchiesToRemoveBeforePlugins()
public boolean isDisableBindCurrentClass()
public void createdGuiceInjector(com.google.inject.Injector injector)
SpincastPlugincreatedGuiceInjector in interface SpincastPluginpublic com.google.inject.Injector getInjector()
public com.google.inject.Module beforePlugins(com.google.inject.Module combinedModule)
combinedModule - the combinaison of all the
Guice modules just before the plugins are applied.public com.google.inject.Module apply(com.google.inject.Module currentModule)
apply in interface SpincastPluginpublic com.google.inject.Module afterPlugins(com.google.inject.Module combinedModule)
combinedModule - the combinaison of all the
Guice modules just after the plugins have been applied.protected com.google.inject.Module addOverridingModules(com.google.inject.Module combinedModule)
public 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)
SpincastContextTypesInterestedsetRequestContextImplementationClass in interface SpincastContextTypesInterestedpublic void setWebsocketContextImplementationClass(Class<? extends WebsocketContext<?>> websocketContextImplementationClass)
SpincastContextTypesInterestedsetWebsocketContextImplementationClass in interface SpincastContextTypesInterestedprotected Class<? extends RequestContext<?>> getRequestContextImplementationClass()
protected Class<? extends WebsocketContext<?>> getWebsocketContextImplementationClass()
public void overridingModule(com.google.inject.Module overridingModule)
public void exactBindingToRemove(com.google.inject.Key<?> key)
public void bindingHierarchyToRemove(Class<?> parentClass)
public void plugin(SpincastPlugin plugin)
public void disableBindCurrentClass()
public void pluginToDisable(String pluginId)
Copyright © 2018. All rights reserved.