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.def; 014 015import org.apache.tapestry5.ioc.ObjectCreator; 016import org.apache.tapestry5.ioc.ServiceBuilderResources; 017import org.apache.tapestry5.ioc.ServiceLifecycle; 018import org.apache.tapestry5.ioc.services.ServiceLifecycleSource; 019 020import java.util.Set; 021 022/** 023 * Service definition derived, by default, from a service builder method. This has been extended in Tapestry 5.1 with 024 * {@link org.apache.tapestry5.ioc.def.ServiceDef2}, which adds additional methods. Tapestry 5.3 added {@link ServiceDef3}. 025 */ 026@SuppressWarnings("rawtypes") 027public interface ServiceDef 028{ 029 /** 030 * Returns an {@link ObjectCreator} that can create the core service implementation. 031 * 032 * @param resources used to resolve dependencies of the service, or access its configuration 033 * @return an object that can (later) be used to instantiate the service itself 034 */ 035 ObjectCreator createServiceCreator(ServiceBuilderResources resources); 036 037 /** 038 * Returns the service id, derived from the method name or the unqualified service interface name. Service ids must 039 * be unique among <em>all</em> services in all modules. Service ids are used in a heavy handed way to support 040 * ultimate disambiguation, but their primary purpose is to support service contribution methods. 041 */ 042 String getServiceId(); 043 044 /** 045 * Returns an optional set of <em>marker annotations</em>. Marker annotations are used to disambiguate services; the 046 * combination of a marker annotation and a service type is expected to be unique. The annotation is placed on the 047 * field or method/constructor parameter and the service is located by combining the marker with service type (the 048 * parameter or field type). 049 * 050 * @return the marker annotations for the service (possibly empty), including any default marker annotations 051 * from the containing module. 052 */ 053 Set<Class> getMarkers(); 054 055 /** 056 * Returns the service interface associated with this service. This is the interface exposed to the outside world, 057 * as well as the one used to build proxies. In cases where the service is <em>not</em> defined in terms of an 058 * interface, this will return the actual implementation class of the service. Services without a true service 059 * interface are <strong>not proxied</strong>, which has a number of ramifications (such as losing lazy 060 * instantiation capabilities and other more interesting lifecycles). 061 */ 062 Class getServiceInterface(); 063 064 /** 065 * Returns the lifecycle defined for the service. This is indicated by adding a 066 * {@link org.apache.tapestry5.ioc.annotations.Scope} annotation to the service builder method for the service. 067 * 068 * Services that are not proxied will ignore their scope; such services are always treated as singletons. 069 * 070 * @see ServiceLifecycle 071 * @see ServiceLifecycleSource 072 */ 073 String getServiceScope(); 074 075 /** 076 * Returns true if the service should be eagerly loaded at Registry startup. 077 * 078 * @see org.apache.tapestry5.ioc.annotations.EagerLoad 079 */ 080 boolean isEagerLoad(); 081}