001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005//     http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.ioc.annotations;
014
015import static java.lang.annotation.ElementType.METHOD;
016import static java.lang.annotation.ElementType.TYPE;
017import static java.lang.annotation.RetentionPolicy.RUNTIME;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.Retention;
021import java.lang.annotation.Target;
022
023/**
024 * An optional annotation that may be placed on a service building method of a module, or on the implementation class
025 * (when using service binding). The annotation overrides the default scope for services (the default being a global
026 * singleton that is instantiated on demand) for an alternate lifecycle. Alternate lifecycles are typically used to bind
027 * a service implementation to a single thread or request. Modules may define new scopes. Each scope should have a
028 * corresponding <a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceLifecycle.html">ServiceLifecycle</a> implementation. The linkage from scope name to service lifecycle occurs via a
029 * contribution to the <a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/ServiceLifecycleSource.html">ServiceLifecycleSource</a> service configuration.
030 *
031 * The annotation may also be placed directly on a service implementation class, when using service binding (via
032 * the <a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceBinder.html">ServiceBinder</a>).
033 *
034 * @see <a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceBinder.html">ScopeConstants</a>.
035 */
036@Target(
037        {TYPE, METHOD})
038@Retention(RUNTIME)
039@Documented
040@UseWith({AnnotationUseContext.SERVICE, AnnotationUseContext.MODULE})
041public @interface Scope
042{
043    /**
044     * An identifier used to look up a non-default <a href="https://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceBinder.html">ServiceLifecycle</a>.
045     */
046    String value();
047}