1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<!--NewPage-->
3<HTML>
4<HEAD>
5<!-- Generated by javadoc (build 1.5.0_16) on Mon Oct 12 16:11:19 PDT 2009 -->
6<TITLE>
7Scope
8</TITLE>
9
10<META NAME="keywords" CONTENT="javax.inject.Scope class">
11
12<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13
14<SCRIPT type="text/javascript">
15function windowTitle()
16{
17    parent.document.title="Scope";
18}
19</SCRIPT>
20<NOSCRIPT>
21</NOSCRIPT>
22
23</HEAD>
24
25<BODY BGCOLOR="white" onload="windowTitle();">
26
27
28<!-- ========= START OF TOP NAVBAR ======= -->
29<A NAME="navbar_top"><!-- --></A>
30<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
31<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
32<TR>
33<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
34<A NAME="navbar_top_firstrow"><!-- --></A>
35<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
36  <TR ALIGN="center" VALIGN="top">
37  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../javax/inject/package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
38  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
39  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
40  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
41  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
42  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
43  </TR>
44</TABLE>
45</TD>
46<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
47</EM>
48</TD>
49</TR>
50
51<TR>
52<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
53&nbsp;<A HREF="../../javax/inject/Qualifier.html" title="annotation in javax.inject"><B>PREV CLASS</B></A>&nbsp;
54&nbsp;<A HREF="../../javax/inject/Singleton.html" title="annotation in javax.inject"><B>NEXT CLASS</B></A></FONT></TD>
55<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
56  <A HREF="../../index.html?javax/inject/Scope.html" target="_top"><B>FRAMES</B></A>  &nbsp;
57&nbsp;<A HREF="Scope.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
58&nbsp;<SCRIPT type="text/javascript">
59  <!--
60  if(window==top) {
61    document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
62  }
63  //-->
64</SCRIPT>
65<NOSCRIPT>
66  <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
67</NOSCRIPT>
68
69
70</FONT></TD>
71</TR>
72<TR>
73<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
74  SUMMARY:&nbsp;REQUIRED&nbsp;|&nbsp;OPTIONAL</FONT></TD>
75<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
76DETAIL:&nbsp;ELEMENT</FONT></TD>
77</TR>
78</TABLE>
79<A NAME="skip-navbar_top"></A>
80<!-- ========= END OF TOP NAVBAR ========= -->
81
82<HR>
83<!-- ======== START OF CLASS DATA ======== -->
84<H2>
85<FONT SIZE="-1">
86javax.inject</FONT>
87<BR>
88Annotation Type Scope</H2>
89<HR>
90<DL>
91<DT><PRE><FONT SIZE="-1">@Target(value=ANNOTATION_TYPE)
92@Retention(value=RUNTIME)
93@Documented
94</FONT>public @interface <B>Scope</B></DL>
95</PRE>
96
97<P>
98Identifies scope annotations. A scope annotation applies to a class
99 containing an injectable constructor and governs how the injector reuses
100 instances of the type. By default, if no scope annotation is present, the
101 injector creates an instance (by injecting the type's constructor), uses
102 the instance for one injection, and then forgets it. If a scope annotation
103 is present, the injector may retain the instance for possible reuse in a
104 later injection. If multiple threads can access a scoped instance, its
105 implementation should be thread safe. The implementation of the scope
106 itself is left up to the injector.
107
108 <p>In the following example, the scope annotation <code>@Singleton</code> ensures
109 that we only have one Log instance:
110
111 <pre>
112   &#064;Singleton
113   class Log {
114     void log(String message) { ... }
115   }</pre>
116
117 <p>The injector generates an error if it encounters more than one scope
118 annotation on the same class or a scope annotation it doesn't support.
119
120 <p>A scope annotation:
121 <ul>
122   <li>is annotated with <code>@Scope</code>, <code>@Retention(RUNTIME)</code>,
123      and typically <code>@Documented</code>.</li>
124   <li>should not have attributes.</li>
125   <li>is typically not <code>@Inherited</code>, so scoping is orthogonal to
126      implementation inheritance.</li>
127   <li>may have restricted usage if annotated with <code>@Target</code>. While
128      this specification covers applying scopes to classes only, some
129      injector configurations might use scope annotations
130      in other places (on factory method results for example).</li>
131 </ul>
132
133 <p>For example:
134
135 <pre>
136   &#064;java.lang.annotation.Documented
137   &#064;java.lang.annotation.Retention(RUNTIME)
138   &#064;javax.inject.Scope
139   public @interface RequestScoped {}</pre>
140
141 <p>Annotating scope annotations with <code>@Scope</code> helps the injector
142 detect the case where a programmer used the scope annotation on a class but
143 forgot to configure the scope in the injector. A conservative injector
144 would generate an error rather than not apply a scope.
145<P>
146
147<P>
148<DL>
149<DT><B>See Also:</B><DD><A HREF="../../javax/inject/Singleton.html" title="annotation in javax.inject"><CODE>@Singleton</CODE></A></DL>
150
151<P>
152
153<P>
154<!-- ========= END OF CLASS DATA ========= -->
155<HR>
156
157
158<!-- ======= START OF BOTTOM NAVBAR ====== -->
159<A NAME="navbar_bottom"><!-- --></A>
160<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
161<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
162<TR>
163<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
164<A NAME="navbar_bottom_firstrow"><!-- --></A>
165<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
166  <TR ALIGN="center" VALIGN="top">
167  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../javax/inject/package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
168  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
169  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
170  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
171  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
172  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
173  </TR>
174</TABLE>
175</TD>
176<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
177</EM>
178</TD>
179</TR>
180
181<TR>
182<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
183&nbsp;<A HREF="../../javax/inject/Qualifier.html" title="annotation in javax.inject"><B>PREV CLASS</B></A>&nbsp;
184&nbsp;<A HREF="../../javax/inject/Singleton.html" title="annotation in javax.inject"><B>NEXT CLASS</B></A></FONT></TD>
185<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
186  <A HREF="../../index.html?javax/inject/Scope.html" target="_top"><B>FRAMES</B></A>  &nbsp;
187&nbsp;<A HREF="Scope.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
188&nbsp;<SCRIPT type="text/javascript">
189  <!--
190  if(window==top) {
191    document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
192  }
193  //-->
194</SCRIPT>
195<NOSCRIPT>
196  <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
197</NOSCRIPT>
198
199
200</FONT></TD>
201</TR>
202<TR>
203<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
204  SUMMARY:&nbsp;REQUIRED&nbsp;|&nbsp;OPTIONAL</FONT></TD>
205<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
206DETAIL:&nbsp;ELEMENT</FONT></TD>
207</TR>
208</TABLE>
209<A NAME="skip-navbar_bottom"></A>
210<!-- ======== END OF BOTTOM NAVBAR ======= -->
211
212<HR>
213<font size='-1'>Copyright (C) 2009 <a href='http://code.google.com/p/atinject/'>The JSR-330 Expert Group</a>. Licensed under the <a href='http://www.apache.org/licenses/LICENSE-2.0'>Apache License</a>, Version 2.0.</font>
214</BODY>
215</HTML>
216