001// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.ioc.annotations; 016 017import java.lang.annotation.Documented; 018import static java.lang.annotation.ElementType.*; 019import java.lang.annotation.Retention; 020import static java.lang.annotation.RetentionPolicy.RUNTIME; 021import java.lang.annotation.Target; 022 023import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*; 024 025/** 026 * This annotation serves is something of the Swiss Army knife for operations related to injection of dependencies into 027 * an arbitrary method of Java Bean. 028 * <p/> 029 * <p> 030 * It marks parameters that should be injected in the IoC container, and it marks fields that should be injected inside 031 * Tapestry components. 032 * <p/> 033 * In terms of the IoC container; normally, resources take precedence over annotations when injecting. The Inject 034 * annotation overrides this default, forcing the resolution of the parameters value via the master 035 * {@link org.apache.tapestry5.ioc.ObjectProvider}, even when the parameter's type matches a type that is normally a 036 * resource. 037 * <p/> 038 * For service implementations, module classes, and other objects constructed via 039 * {@link org.apache.tapestry5.ioc.ObjectLocator#autobuild(Class)}, this annotation indicates that an injection is 040 * desired on the field, as with fields of a Tapestry component. 041 * <p/> 042 * In terms of the IoC container, the Inject annotation is only used on parameters to service builder methods (and 043 * contributor and decorator methods) and on module class constructors. constructors. However, inside Tapestry 044 * components (<em>and only inside components</em>), it may be applied to fields. On fields that require injection, the 045 * Inject annotation is <em>required</em>. 046 * <p/> 047 * Finally, on a constructor, this is used to indicate <em>which</em> constructor should be used when more than one is 048 * available. 049 * 050 * @see org.apache.tapestry5.ioc.ObjectProvider 051 */ 052@Target( 053{ PARAMETER, FIELD, CONSTRUCTOR }) 054@Retention(RUNTIME) 055@Documented 056@UseWith( 057{ COMPONENT, MIXIN, PAGE, SERVICE }) 058public @interface Inject 059{ 060 061}