001 // Copyright 2006, 2007, 2008 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
015 package org.apache.tapestry5.ioc.annotations;
016
017 import java.lang.annotation.Documented;
018 import static java.lang.annotation.ElementType.*;
019 import java.lang.annotation.Retention;
020 import static java.lang.annotation.RetentionPolicy.RUNTIME;
021 import java.lang.annotation.Target;
022
023 /**
024 * This annotation serves is something of the Swiss Army knife for operations related to injection of dependencies into
025 * an arbitrary method of Java Bean.
026 * <p/>
027 * <p>It marks parameters that should be injected in the IoC container, and it marks fields that should be injected
028 * inside Tapestry components.
029 * <p/>
030 * In terms of the IoC container; normally, resources take precedence over annotations when injecting. The Inject
031 * annotation overrides this default, forcing the resolution of the parameters value via the master {@link
032 * org.apache.tapestry5.ioc.ObjectProvider}, even when the parameter's type matches a type that is normally a resource.
033 * This is most often used in conjunction with {@link org.apache.tapestry5.ioc.annotations.Value} annotation when
034 * injecting a string, as normally, the String would be matched as the service id.
035 * <p/>
036 * For service implementations, module classes, and other objects constructed via {@link
037 * org.apache.tapestry5.ioc.ObjectLocator#autobuild(Class)}, this annotation indicates that an injection is desired on
038 * the field, as with fields of a Tapestry component.
039 * <p/>
040 * In terms of the IoC container, the Inject annotation is only used on parameters to service builder methods (and
041 * contributor and decorator methods) and on module class constructors. constructors. However, inside Tapestry
042 * components (<em>and only inside components</em>), it may be applied to fields. On fields that require injection, the
043 * Inject annotation is <em>required</em>.
044 * <p/>
045 * Finally, on a constructor, this is used to indicate <em>which</em> constructor should be used when more than one is
046 * available.
047 *
048 * @see org.apache.tapestry5.ioc.ObjectProvider
049 */
050 @Target(
051 {PARAMETER, FIELD, CONSTRUCTOR})
052 @Retention(RUNTIME)
053 @Documented
054 public @interface Inject
055 {
056
057 }