1 // Copyright 2006, 2007, 2008 The Apache Software Foundation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package org.apache.tapestry5.ioc.annotations; 16 17 import java.lang.annotation.Documented; 18 import static java.lang.annotation.ElementType.*; 19 import java.lang.annotation.Retention; 20 import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 import java.lang.annotation.Target; 22 23 /** 24 * This annotation serves is something of the Swiss Army knife for operations related to injection of dependencies into 25 * an arbitrary method of Java Bean. 26 * <p/> 27 * <p>It marks parameters that should be injected in the IoC container, and it marks fields that should be injected 28 * inside Tapestry components. 29 * <p/> 30 * In terms of the IoC container; normally, resources take precedence over annotations when injecting. The Inject 31 * annotation overrides this default, forcing the resolution of the parameters value via the master {@link 32 * org.apache.tapestry5.ioc.ObjectProvider}, even when the parameter's type matches a type that is normally a resource. 33 * This is most often used in conjunction with {@link org.apache.tapestry5.ioc.annotations.Value} annotation when 34 * injecting a string, as normally, the String would be matched as the service id. 35 * <p/> 36 * For service implementations, module classes, and other objects constructed via {@link 37 * org.apache.tapestry5.ioc.ObjectLocator#autobuild(Class)}, this annotation indicates that an injection is desired on 38 * the field, as with fields of a Tapestry component. 39 * <p/> 40 * In terms of the IoC container, the Inject annotation is only used on parameters to service builder methods (and 41 * contributor and decorator methods) and on module class constructors. constructors. However, inside Tapestry 42 * components (<em>and only inside components</em>), it may be applied to fields. On fields that require injection, the 43 * Inject annotation is <em>required</em>. 44 * <p/> 45 * Finally, on a constructor, this is used to indicate <em>which</em> constructor should be used when more than one is 46 * available. 47 * 48 * @see org.apache.tapestry5.ioc.ObjectProvider 49 */ 50 @Target( 51 {PARAMETER, FIELD, CONSTRUCTOR}) 52 @Retention(RUNTIME) 53 @Documented 54 public @interface Inject 55 { 56 57 }