Package org.spincast.core.guice
Class GuiceTweaker
java.lang.Object
org.spincast.core.guice.GuiceTweaker
- All Implemented Interfaces:
SpincastContextTypesInterested
,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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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
void
exactBindingToRemove
(com.google.inject.Key<?> key) An exact binding to remove from the combined modules.protected Set<com.google.inject.Key<?>>
protected List<SpincastPlugin>
getId()
The id of the plugin.com.google.inject.Injector
protected Set<com.google.inject.Module>
If required, the ids of plugins that shouldn't be installed.protected Class<? extends RequestContext<?>>
protected Class<? extends WebsocketContext<?>>
boolean
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 Details
-
threadLocal
-
PLUGIN_ID
-
-
Constructor Details
-
GuiceTweaker
public GuiceTweaker()
-
-
Method Details
-
getId
Description copied from interface:SpincastPlugin
The id of the plugin.- Specified by:
getId
in interfaceSpincastPlugin
-
getExtraPlugins
-
getOverridingModules
-
getExactBindingsToRemoveBeforePlugins
-
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 interfaceSpincastPlugin
-
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 interfaceSpincastPlugin
- 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
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 interfaceSpincastPlugin
-
setRequestContextImplementationClass
public void setRequestContextImplementationClass(Class<? extends RequestContext<?>> requestContextImplementationClass) Description copied from interface:SpincastContextTypesInterested
The implementation class to use for RequestContext.- Specified by:
setRequestContextImplementationClass
in interfaceSpincastContextTypesInterested
-
setWebsocketContextImplementationClass
public void setWebsocketContextImplementationClass(Class<? extends WebsocketContext<?>> websocketContextImplementationClass) Description copied from interface:SpincastContextTypesInterested
The implementation class to use for WebsocletContext.- Specified by:
setWebsocketContextImplementationClass
in interfaceSpincastContextTypesInterested
-
getRequestContextImplementationClass
-
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
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
Adds an extra plugin to be applied when the Guice context is created. -
disableBindCurrentClass
public void disableBindCurrentClass() -
pluginToDisable
-