    001// Copyright 2006, 2007, 2008, 2009 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 org.apache.tapestry5.ioc.ServiceBinder;
    018import org.apache.tapestry5.ioc.ServiceLifecycle;
    019import org.apache.tapestry5.ioc.services.ServiceLifecycleSource;
    020
    021import java.lang.annotation.Documented;
    022import static java.lang.annotation.ElementType.METHOD;
    023import static java.lang.annotation.ElementType.TYPE;
    024import java.lang.annotation.Retention;
    025import static java.lang.annotation.RetentionPolicy.RUNTIME;
    026import java.lang.annotation.Target;
    027
    028/**
    029 * An optional annotation that may be placed on a service building method of a module, or on the implementation class
    030 * (when using service binding). The annotation overrides the default scope for services (the default being a global
    031 * singleton that is instantiated on demand) for an alternate lifecycle. Alternate lifecycles are typically used to bind
    032 * a service implementation to a single thread or request. Modules may define new scopes. Each scope should have a
    033 * corresponding {@link ServiceLifecycle} implementation. The linkage from scope name to service lifecycle occurs via a
    034 * contribution to the {@link ServiceLifecycleSource} service configuration.
    035 * <p/>
    036 * The annotation may also be placed directly on a service implementation class, when using service binding (via
    037 * the {@link ServiceBinder}).
    038 *
    039 * @see org.apache.tapestry5.ioc.ScopeConstants
    040 */
    041@Target(
    042        {TYPE, METHOD})
    043@Retention(RUNTIME)
    044@Documented
    045@UseWith({AnnotationUseContext.SERVICE, AnnotationUseContext.MODULE})
    046public @interface Scope
    047{
    048    /**
    049     * An identifier used to look up a non-default {@link ServiceLifecycle}.
    050     */
    051    String value();
    052}