    001// Copyright 2006, 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
    015package org.apache.tapestry5.ioc;
    016
    017import org.apache.tapestry5.commons.ObjectCreator;
    018
    019/**
    020 * Allows certain types of lifecycles to control exactly how services are instantiated.
    021 */
    022public interface ServiceLifecycle
    023{
    024    /**
    025     * Returns the same creator, or a new one, that encapsulates the creation of the core service implementation.
    026     *
    027     * @param resources source of information about the service to be created, and source of additional services or
    028     *                  other resources that may be needed when constructing the core service implementation
    029     * @param creator   object capable of creating the service implementation on demand. This is a wrapper around the
    030     *                  service's builder method.
    031     * @return the service or equivalent service proxy
    032     */
    033    Object createService(ServiceResources resources, ObjectCreator creator);
    034
    035    /**
    036     * Returns true if the lifecycle is a singleton (a service that will only be created once).  Return false if the
    037     * underlying service instance may be created multiple times (for example, the {@link
    038     * org.apache.tapestry5.ioc.ScopeConstants#PERTHREAD} scope}. A future version of Tapestry IoC may optimize for the
    039     * later case.
    040     *
    041     * @return true for singletons, false   for services that can be repeatedly constructed
    042     */
    043    boolean isSingleton();
    044}