public.javadoc.org.spincast.core.guice.GuiceTweaker.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
GuiceTweaker (org.spincast:spincast-framework 1.13.0 API)
org.spincast.core.guice
Class GuiceTweaker
- java.lang.Object
-
- org.spincast.core.guice.GuiceTweaker
-
- All Implemented Interfaces:
- SpincastContextTypesInterested, SpincastPlugin
public class GuiceTweaker
extends Object
implements SpincastPlugin
Spincast plugin made available through a ThreadLocal.
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.
-
-
Field Summary
Fields
Modifier and Type
Field and Description
static String
PLUGIN_ID
static ThreadLocal<GuiceTweaker>
threadLocal
-
Constructor Summary
Constructors
Constructor and Description
GuiceTweaker()
-
Method Summary
All Methods Instance Methods Concrete Methods
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.
-
-
Field Detail
-
threadLocal
public static final ThreadLocal<GuiceTweaker> threadLocal
-
PLUGIN_ID
public static final String PLUGIN_ID
-
Method Detail
-
getId
public String getId()
Description copied from interface: SpincastPlugin
The id of the plugin.
- Specified by:
getId
in interface SpincastPlugin
-
getExtraPlugins
protected List<SpincastPlugin> getExtraPlugins()
-
getOverridingModules
protected Set<com.google.inject.Module> getOverridingModules()
-
getExactBindingsToRemoveBeforePlugins
protected Set<com.google.inject.Key<?>> getExactBindingsToRemoveBeforePlugins()
-
getBindingsHierarchiesToRemoveBeforePlugins
public Set<Class<?>> getBindingsHierarchiesToRemoveBeforePlugins()
-
isDisableBindCurrentClass
public boolean isDisableBindCurrentClass()
-
createdGuiceInjector
public void createdGuiceInjector(com.google.inject.Injector injector)
Description copied from interface: SpincastPlugin
Once all the plugins have been applied,
this method is called with the resulting
Guice injector.
- Specified by:
createdGuiceInjector
in interface SpincastPlugin
-
getInjector
public com.google.inject.Injector getInjector()
-
beforePlugins
public com.google.inject.Module beforePlugins(com.google.inject.Module combinedModule)
Ran before the plugins are applied in
SpincastBootstrapper.
- Parameters:
combinedModule
- the combinaison of all the
Guice modules just before the plugins are applied.
-
apply
public com.google.inject.Module apply(com.google.inject.Module currentModule)
Ran as a regular plugin.
- Specified by:
apply
in interface SpincastPlugin
- Returns:
- an ajusted Guice module.
-
afterPlugins
public com.google.inject.Module afterPlugins(com.google.inject.Module combinedModule)
Ran after the plugins are applied in
SpincastBootstrapper.
- Parameters:
combinedModule
- the combinaison of all the
Guice modules just after the plugins have been applied.
-
addOverridingModules
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.
-
getPluginsToDisable
public Set<String> getPluginsToDisable()
Description copied from interface: SpincastPlugin
If required, the ids of plugins that shouldn't
be installed.
This plugin is repsonsible to bind any components
that won't be bound because it marks some plugins
as "to be ignored".
- Specified by:
getPluginsToDisable
in interface SpincastPlugin
-
setRequestContextImplementationClass
public void setRequestContextImplementationClass(Class<? extends RequestContext<?>> requestContextImplementationClass)
Description copied from interface: SpincastContextTypesInterested
The implementation class to use for RequestContext.
- Specified by:
setRequestContextImplementationClass
in interface SpincastContextTypesInterested
-
setWebsocketContextImplementationClass
public void setWebsocketContextImplementationClass(Class<? extends WebsocketContext<?>> websocketContextImplementationClass)
Description copied from interface: SpincastContextTypesInterested
The implementation class to use for WebsocletContext.
- Specified by:
setWebsocketContextImplementationClass
in interface SpincastContextTypesInterested
-
getRequestContextImplementationClass
protected Class<? extends RequestContext<?>> getRequestContextImplementationClass()
-
getWebsocketContextImplementationClass
protected Class<? extends WebsocketContext<?>> getWebsocketContextImplementationClass()
-
overridingModule
public void overridingModule(com.google.inject.Module overridingModule)
Adds an overriding Module. The bindings of this Module
will be applied before the plugins run in SpincastBootstrapper.
-
exactBindingToRemove
public void exactBindingToRemove(com.google.inject.Key<?> key)
An exact binding to remove from the combined modules.
This will be done before the plugins run
in SpincastBootstrapper.
-
bindingHierarchyToRemove
public void bindingHierarchyToRemove(Class<?> parentClass)
An binding hierarchy to remove from the combined modules. All
bindings implementing or extending the specified parent
class, directly or indirectly, will be removed.
This will be done before the plugins run
in SpincastBootstrapper.
-
plugin
public void plugin(SpincastPlugin plugin)
Adds an extra plugin to be applied when
the Guice context is created.
-
disableBindCurrentClass
public void disableBindCurrentClass()
-
pluginToDisable
public void pluginToDisable(String pluginId)
Copyright © 2019. All rights reserved.