roboguice.inject
Class ContextScope

java.lang.Object
  extended by roboguice.inject.ContextScope
All Implemented Interfaces:
com.google.inject.Scope

public class ContextScope
extends Object
implements com.google.inject.Scope

Scopes the injector based on the current context. Any usage of this class must call #enter(Context) before performing any operations with the injector, and do so within a synchronized block on the ContextScope.class, eg: synchronized(ContextScope.class) { scope.enter(context); // do something, eg. // injector.injectMembers(this); } If you're using ContextScopedRoboInjector (which is the RoboGuice default), this is done for you automatically. If you're trying to use a Provider, you must either use ContextScopedProvider instead, or do your own synchronization and scope.enter() call.

Author:
Mike Burton
See Also:
ContextScopedRoboInjector

Field Summary
protected  android.app.Application application
           
protected  Map<com.google.inject.Key<?>,Object> applicationScopedObjects
           
protected  ThreadLocal<Stack<WeakReference<android.content.Context>>> contextThreadLocal
           
 
Constructor Summary
ContextScope(android.app.Application application)
           
 
Method Summary
 void enter(android.content.Context context)
          You MUST perform any injector operations inside a synchronized(ContextScope.class) block that starts with scope.enter(context) if working in a multithreaded environment
 void exit(android.content.Context context)
           
 Stack<WeakReference<android.content.Context>> getContextStack()
           
protected  Map<com.google.inject.Key<?>,Object> getScopedObjectMap(android.content.Context origContext)
           
<T> com.google.inject.Provider<T>
scope(com.google.inject.Key<T> key, com.google.inject.Provider<T> unscoped)
           
 
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 Detail

contextThreadLocal

protected ThreadLocal<Stack<WeakReference<android.content.Context>>> contextThreadLocal

applicationScopedObjects

protected Map<com.google.inject.Key<?>,Object> applicationScopedObjects

application

protected android.app.Application application
Constructor Detail

ContextScope

public ContextScope(android.app.Application application)
Method Detail

enter

public void enter(android.content.Context context)
You MUST perform any injector operations inside a synchronized(ContextScope.class) block that starts with scope.enter(context) if working in a multithreaded environment

Parameters:
context - the context to enter
See Also:
ContextScope, ContextScopedRoboInjector, ContextScopedProvider

exit

public void exit(android.content.Context context)

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

getContextStack

public Stack<WeakReference<android.content.Context>> getContextStack()

getScopedObjectMap

protected Map<com.google.inject.Key<?>,Object> getScopedObjectMap(android.content.Context origContext)


Copyright © 2012. All Rights Reserved.