Issue 35: override to no scope; Issue 56: OutOfScopeException.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@304 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/OutOfScopeException.java b/src/com/google/inject/OutOfScopeException.java
new file mode 100644
index 0000000..ba60347
--- /dev/null
+++ b/src/com/google/inject/OutOfScopeException.java
@@ -0,0 +1,22 @@
+package com.google.inject;
+
+/**
+ * Thrown from {@link Provider#get} when an attempt is made to access a scoped
+ * object while the scope in question is not currently active.
+ *
+ * @author kevinb@google.com (Kevin Bourrillion)
+ */
+public class OutOfScopeException extends RuntimeException {
+
+  public OutOfScopeException(String message) {
+    super(message);
+  }
+
+  public OutOfScopeException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public OutOfScopeException(Throwable cause) {
+    super(cause);
+  }
+}
diff --git a/src/com/google/inject/Provider.java b/src/com/google/inject/Provider.java
index fc52af5..1b3e8b0 100644
--- a/src/com/google/inject/Provider.java
+++ b/src/com/google/inject/Provider.java
@@ -50,6 +50,9 @@
 
   /**
    * Provides an instance of {@code T}. Must never return {@code null}.
+   *
+   * @throws OutOfScopeException when an attempt is made to access a scoped
+   *     object while the scope in question is not currently active
    */
   T get();
 }
diff --git a/src/com/google/inject/Scopes.java b/src/com/google/inject/Scopes.java
index 80f8967..31f3d69 100644
--- a/src/com/google/inject/Scopes.java
+++ b/src/com/google/inject/Scopes.java
@@ -69,6 +69,25 @@
   };
 
   /**
+   * No scope; the same as not applying any scope at all.  Each time the
+   * Injector obtains an instance of an object with "no scope", it injects this
+   * instance then immediately forgets it.  When the next request for the same
+   * binding arrives it will need to obtain the instance over again.
+   *
+   * <p>This exists only in case a class has been annotated with a scope
+   * annotation such as {@link Singleton @Singleton}, and you need to override
+   * this to "no scope" in your binding.
+   */
+  public static final Scope NO_SCOPE = new Scope() {
+    public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
+      return unscoped;
+    }
+    public String toString() {
+      return "Scopes.NO_SCOPE";
+    }
+  };
+
+  /**
    * Gets the scope for a type based on its annotations. Returns {@code null}
    * if none specified.
    *