Class SpincastRequestScope

java.lang.Object
org.spincast.core.guice.SpincastRequestScope
All Implemented Interfaces:
com.google.inject.Scope

public class SpincastRequestScope extends Object implements com.google.inject.Scope
Guice scope for a request.

Modified from: https://github.com/google/guice/wiki/CustomScopes:

Scopes a single execution of a block of code. Apply this scope with a try/finally block:


   scope.enter();
   try {
     // explicitly seed some seed objects...
     scope.seed(Key.get(SomeObject.class), someObject);
     // create and access scoped objects
   } finally {
     scope.exit();
   }
 
The scope can be initialized with one or more seed values by calling seed(key, value) before the injector will be called upon to provide for this key. A typical use is for a servlet filter to enter/exit the scope, representing a Request Scope, and seed HttpServletRequest and HttpServletResponse. For each key inserted with seed(), you must include a corresponding binding:
   bind(key)
       .toProvider(SimpleScope.<KeyClass>seededKeyProvider())
       .in(ScopeAnnotation.class);
 

Author:
Jesse Wilson, Fedor Karpelevitch
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    protected <T> Map<com.google.inject.Key<?>,Object>
    getScopedObjectMap(com.google.inject.Key<T> key)
     
    static <T> com.google.inject.Provider<T>
    getSeedErrorProvider(com.google.inject.Key key)
    Returns a provider that always throws exception complaining that the object in question must be seeded before it can be injected.
    <T> com.google.inject.Provider<T>
    scope(com.google.inject.Key<T> key, com.google.inject.Provider<T> unscoped)
     
    <T> void
    seed(com.google.inject.Key<T> key, T value)
     
    <T> void
    seed(Class<T> clazz, T value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.google.inject.Scope

    toString
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
  • Constructor Details

    • SpincastRequestScope

      public SpincastRequestScope()
  • Method Details

    • enter

      public void enter()
    • exit

      public void exit()
    • seed

      public <T> void seed(com.google.inject.Key<T> key, T value)
    • seed

      public <T> void seed(Class<T> clazz, T value)
    • scope

      public <T> com.google.inject.Provider<T> scope(com.google.inject.Key<T> key, com.google.inject.Provider<T> unscoped)
      Specified by:
      scope in interface com.google.inject.Scope
    • getScopedObjectMap

      protected <T> Map<com.google.inject.Key<?>,Object> getScopedObjectMap(com.google.inject.Key<T> key)
    • getSeedErrorProvider

      public static <T> com.google.inject.Provider<T> getSeedErrorProvider(com.google.inject.Key key)
      Returns a provider that always throws exception complaining that the object in question must be seeded before it can be injected.
      Returns:
      typed provider