318 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			318 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 | |
| <!--NewPage-->
 | |
| <HTML>
 | |
| <HEAD>
 | |
| <!-- Generated by javadoc (build 1.5.0_16) on Mon Oct 12 16:11:19 PDT 2009 -->
 | |
| <TITLE>
 | |
| Inject
 | |
| </TITLE>
 | |
| 
 | |
| <META NAME="keywords" CONTENT="javax.inject.Inject class">
 | |
| 
 | |
| <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
 | |
| 
 | |
| <SCRIPT type="text/javascript">
 | |
| function windowTitle()
 | |
| {
 | |
|     parent.document.title="Inject";
 | |
| }
 | |
| </SCRIPT>
 | |
| <NOSCRIPT>
 | |
| </NOSCRIPT>
 | |
| 
 | |
| </HEAD>
 | |
| 
 | |
| <BODY BGCOLOR="white" onload="windowTitle();">
 | |
| 
 | |
| 
 | |
| <!-- ========= START OF TOP NAVBAR ======= -->
 | |
| <A NAME="navbar_top"><!-- --></A>
 | |
| <A HREF="#skip-navbar_top" title="Skip navigation links"></A>
 | |
| <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
 | |
| <TR>
 | |
| <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
 | |
| <A NAME="navbar_top_firstrow"><!-- --></A>
 | |
| <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
 | |
|   <TR ALIGN="center" VALIGN="top">
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../javax/inject/package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev">  <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
 | |
|   </TR>
 | |
| </TABLE>
 | |
| </TD>
 | |
| <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
 | |
| </EM>
 | |
| </TD>
 | |
| </TR>
 | |
| 
 | |
| <TR>
 | |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 | |
|  PREV CLASS 
 | |
|  <A HREF="../../javax/inject/Named.html" title="annotation in javax.inject"><B>NEXT CLASS</B></A></FONT></TD>
 | |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 | |
|   <A HREF="../../index.html?javax/inject/Inject.html" target="_top"><B>FRAMES</B></A>   
 | |
|  <A HREF="Inject.html" target="_top"><B>NO FRAMES</B></A>   
 | |
|  <SCRIPT type="text/javascript">
 | |
|   <!--
 | |
|   if(window==top) {
 | |
|     document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
 | |
|   }
 | |
|   //-->
 | |
| </SCRIPT>
 | |
| <NOSCRIPT>
 | |
|   <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
 | |
| </NOSCRIPT>
 | |
| 
 | |
| 
 | |
| </FONT></TD>
 | |
| </TR>
 | |
| <TR>
 | |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
 | |
|   SUMMARY: REQUIRED | OPTIONAL</FONT></TD>
 | |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
 | |
| DETAIL: ELEMENT</FONT></TD>
 | |
| </TR>
 | |
| </TABLE>
 | |
| <A NAME="skip-navbar_top"></A>
 | |
| <!-- ========= END OF TOP NAVBAR ========= -->
 | |
| 
 | |
| <HR>
 | |
| <!-- ======== START OF CLASS DATA ======== -->
 | |
| <H2>
 | |
| <FONT SIZE="-1">
 | |
| javax.inject</FONT>
 | |
| <BR>
 | |
| Annotation Type Inject</H2>
 | |
| <HR>
 | |
| <DL>
 | |
| <DT><PRE><FONT SIZE="-1">@Target(value={METHOD,CONSTRUCTOR,FIELD})
 | |
| @Retention(value=RUNTIME)
 | |
| @Documented
 | |
| </FONT>public @interface <B>Inject</B></DL>
 | |
| </PRE>
 | |
| 
 | |
| <P>
 | |
| Identifies injectable constructors, methods, and fields. May apply to static
 | |
|  as well as instance members. An injectable member may have any access
 | |
|  modifier (private, package-private, protected, public). Constructors are
 | |
|  injected first, followed by fields, and then methods. Fields and methods
 | |
|  in superclasses are injected before those in subclasses. Ordering of
 | |
|  injection among fields and among methods in the same class is not specified.
 | |
| 
 | |
|  <p>Injectable constructors are annotated with <code>@Inject</code> and accept
 | |
|  zero or more dependencies as arguments. <code>@Inject</code> can apply to at most
 | |
|  one constructor per class.
 | |
| 
 | |
|  <p><tt><blockquote style="padding-left: 2em; text-indent: -2em;">@Inject
 | |
|        <i>ConstructorModifiers<sub>opt</sub></i>
 | |
|        <i>SimpleTypeName</i>(<i>FormalParameterList<sub>opt</sub></i>)
 | |
|        <i>Throws<sub>opt</sub></i>
 | |
|        <i>ConstructorBody</i></blockquote></tt>
 | |
| 
 | |
|  <p><code>@Inject</code> is optional for public, no-argument constructors when no
 | |
|  other constructors are present. This enables injectors to invoke default
 | |
|  constructors.
 | |
| 
 | |
|  <p><tt><blockquote style="padding-left: 2em; text-indent: -2em;">
 | |
|        @Inject<sub><i>opt</i></sub>
 | |
|        <i>Annotations<sub>opt</sub></i>
 | |
|        public
 | |
|        <i>SimpleTypeName</i>()
 | |
|        <i>Throws<sub>opt</sub></i>
 | |
|        <i>ConstructorBody</i></blockquote></tt>
 | |
| 
 | |
|  <p>Injectable fields:
 | |
|  <ul>
 | |
|    <li>are annotated with <code>@Inject</code>.
 | |
|    <li>are not final.
 | |
|    <li>may have any otherwise valid name.</li></ul>
 | |
| 
 | |
|  <p><tt><blockquote style="padding-left: 2em; text-indent: -2em;">@Inject
 | |
|        <i>FieldModifiers<sub>opt</sub></i>
 | |
|        <i>Type</i>
 | |
|        <i>VariableDeclarators</i>;</blockquote></tt>
 | |
| 
 | |
|  <p>Injectable methods:
 | |
|  <ul>
 | |
|    <li>are annotated with <code>@Inject</code>.</li>
 | |
|    <li>are not abstract.</li>
 | |
|    <li>do not declare type parameters of their own.</li>
 | |
|    <li>may return a result</li>
 | |
|    <li>may have any otherwise valid name.</li>
 | |
|    <li>accept zero or more dependencies as arguments.</li></ul>
 | |
| 
 | |
|  <p><tt><blockquote style="padding-left: 2em; text-indent: -2em;">@Inject
 | |
|        <i>MethodModifiers<sub>opt</sub></i>
 | |
|        <i>ResultType</i>
 | |
|        <i>Identifier</i>(<i>FormalParameterList<sub>opt</sub></i>)
 | |
|        <i>Throws<sub>opt</sub></i>
 | |
|        <i>MethodBody</i></blockquote></tt>
 | |
| 
 | |
|  <p>The injector ignores the result of an injected method, but
 | |
|  non-<code>void</code> return types are allowed to support use of the method in
 | |
|  other contexts (builder-style method chaining, for example).
 | |
| 
 | |
|  <p>Examples:
 | |
| 
 | |
|  <pre>
 | |
|    public class Car {
 | |
|      // Injectable constructor
 | |
|      @Inject public Car(Engine engine) { ... }
 | |
| 
 | |
|      // Injectable field
 | |
|      @Inject private Provider<Seat> seatProvider;
 | |
| 
 | |
|      // Injectable package-private method
 | |
|      @Inject void install(Windshield windshield, Trunk trunk) { ... }
 | |
|    }</pre>
 | |
| 
 | |
|  <p>A method annotated with <code>@Inject</code> that overrides another method
 | |
|  annotated with <code>@Inject</code> will only be injected once per injection
 | |
|  request per instance. A method with <i>no</i> <code>@Inject</code> annotation
 | |
|  that overrides a method annotated with <code>@Inject</code> will not be
 | |
|  injected.
 | |
| 
 | |
|  <p>Injection of members annotated with <code>@Inject</code> is required. While an
 | |
|  injectable member may use any accessibility modifier (including
 | |
|  <tt>private</tt>), platform or injector limitations (like security
 | |
|  restrictions or lack of reflection support) might preclude injection
 | |
|  of non-public members.
 | |
| 
 | |
|  <h3>Qualifiers</h3>
 | |
| 
 | |
|  <p>A <A HREF="../../javax/inject/Qualifier.html" title="annotation in javax.inject">qualifier</A> may annotate an injectable field
 | |
|  or parameter and, combined with the type, identify the implementation to
 | |
|  inject. Qualifiers are optional, and when used with <code>@Inject</code> in
 | |
|  injector-independent classes, no more than one qualifier should annotate a
 | |
|  single field or parameter. The qualifiers are bold in the following example:
 | |
| 
 | |
|  <pre>
 | |
|    public class Car {
 | |
|      @Inject private <b>@Leather</b> Provider<Seat> seatProvider;
 | |
| 
 | |
|      @Inject void install(<b>@Tinted</b> Windshield windshield,
 | |
|          <b>@Big</b> Trunk trunk) { ... }
 | |
|    }</pre>
 | |
| 
 | |
|  <p>If one injectable method overrides another, the overriding method's
 | |
|  parameters do not automatically inherit qualifiers from the overridden
 | |
|  method's parameters.
 | |
| 
 | |
|  <h3>Injectable Values</h3>
 | |
| 
 | |
|  <p>For a given type T and optional qualifier, an injector must be able to
 | |
|  inject a user-specified class that:
 | |
| 
 | |
|  <ol type="a">
 | |
|    <li>is assignment compatible with T and</li>
 | |
|    <li>has an injectable constructor.</li>
 | |
|  </ol>
 | |
| 
 | |
|  <p>For example, the user might use external configuration to pick an
 | |
|  implementation of T. Beyond that, which values are injected depend upon the
 | |
|  injector implementation and its configuration.
 | |
| 
 | |
|  <h3>Circular Dependencies</h3>
 | |
| 
 | |
|  <p>Detecting and resolving circular dependencies is left as an exercise for
 | |
|  the injector implementation. Circular dependencies between two constructors
 | |
|  is an obvious problem, but you can also have a circular dependency between
 | |
|  injectable fields or methods:
 | |
| 
 | |
|  <pre>
 | |
|    class A {
 | |
|      @Inject B b;
 | |
|    }
 | |
|    class B {
 | |
|      @Inject A a;
 | |
|    }</pre>
 | |
| 
 | |
|  <p>When constructing an instance of <code>A</code>, a naive injector
 | |
|  implementation might go into an infinite loop constructing an instance of
 | |
|  <code>B</code> to set on <code>A</code>, a second instance of <code>A</code> to set on
 | |
|  <code>B</code>, a second instance of <code>B</code> to set on the second instance of
 | |
|  <code>A</code>, and so on.
 | |
| 
 | |
|  <p>A conservative injector might detect the circular dependency at build
 | |
|  time and generate an error, at which point the programmer could break the
 | |
|  circular dependency by injecting <A HREF="../../javax/inject/Provider.html" title="interface in javax.inject"><CODE>Provider<A></CODE></A> or <code>Provider<B></code> instead of <code>A</code> or <code>B</code> respectively. Calling <A HREF="../../javax/inject/Provider.html#get()"><CODE>get()</CODE></A> on the provider directly from the constructor or
 | |
|  method it was injected into defeats the provider's ability to break up
 | |
|  circular dependencies. In the case of method or field injection, scoping
 | |
|  one of the dependencies (using <A HREF="../../javax/inject/Singleton.html" title="annotation in javax.inject">singleton scope</A>, for
 | |
|  example) may also enable a valid circular relationship.
 | |
| <P>
 | |
| 
 | |
| <P>
 | |
| <DL>
 | |
| <DT><B>See Also:</B><DD><A HREF="../../javax/inject/Qualifier.html" title="annotation in javax.inject"><CODE>@Qualifier</CODE></A>, 
 | |
| <A HREF="../../javax/inject/Provider.html" title="interface in javax.inject"><CODE>Provider</CODE></A></DL>
 | |
| 
 | |
| <P>
 | |
| 
 | |
| <P>
 | |
| <!-- ========= END OF CLASS DATA ========= -->
 | |
| <HR>
 | |
| 
 | |
| 
 | |
| <!-- ======= START OF BOTTOM NAVBAR ====== -->
 | |
| <A NAME="navbar_bottom"><!-- --></A>
 | |
| <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
 | |
| <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
 | |
| <TR>
 | |
| <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
 | |
| <A NAME="navbar_bottom_firstrow"><!-- --></A>
 | |
| <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
 | |
|   <TR ALIGN="center" VALIGN="top">
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../javax/inject/package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev">  <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
 | |
|   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
 | |
|   </TR>
 | |
| </TABLE>
 | |
| </TD>
 | |
| <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
 | |
| </EM>
 | |
| </TD>
 | |
| </TR>
 | |
| 
 | |
| <TR>
 | |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 | |
|  PREV CLASS 
 | |
|  <A HREF="../../javax/inject/Named.html" title="annotation in javax.inject"><B>NEXT CLASS</B></A></FONT></TD>
 | |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 | |
|   <A HREF="../../index.html?javax/inject/Inject.html" target="_top"><B>FRAMES</B></A>   
 | |
|  <A HREF="Inject.html" target="_top"><B>NO FRAMES</B></A>   
 | |
|  <SCRIPT type="text/javascript">
 | |
|   <!--
 | |
|   if(window==top) {
 | |
|     document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
 | |
|   }
 | |
|   //-->
 | |
| </SCRIPT>
 | |
| <NOSCRIPT>
 | |
|   <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
 | |
| </NOSCRIPT>
 | |
| 
 | |
| 
 | |
| </FONT></TD>
 | |
| </TR>
 | |
| <TR>
 | |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
 | |
|   SUMMARY: REQUIRED | OPTIONAL</FONT></TD>
 | |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
 | |
| DETAIL: ELEMENT</FONT></TD>
 | |
| </TR>
 | |
| </TABLE>
 | |
| <A NAME="skip-navbar_bottom"></A>
 | |
| <!-- ======== END OF BOTTOM NAVBAR ======= -->
 | |
| 
 | |
| <HR>
 | |
| <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>
 | |
| </BODY>
 | |
| </HTML>
 |