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