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 Details

  • Constructor Details

    • GuiceTweaker

      public GuiceTweaker()
  • Method Details

    • 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)