1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.di; 20 21 import java.util.function.Supplier; 22 23 import org.apache.maven.api.annotations.Experimental; 24 import org.apache.maven.api.annotations.Nonnull; 25 26 /** 27 * A {@code Scope} defines how visible instances are when managed by a {@link org.apache.maven.di.Injector}. 28 * Typically, instances are created with <i>no scope</i>, meaning they don’t retain any state from the 29 * framework’s perspective: the {@code Injector} generates the instance, injects it into the necessary class, 30 * and then immediately forgets it. By linking a scope to a specific binding, the created instance can be 31 * “remembered” and reused for future injections. 32 * <p> 33 * Instances are associated to a given scope by means of a {@link org.apache.maven.api.di.Scope @Scope} 34 * annotation, usually put on another annotation. For example, the {@code @Singleton} annotation is used 35 * to indicate that a given binding should be scoped as a singleton. 36 * <p> 37 * The following scopes are currently supported: 38 * <ul> 39 * <li>{@link org.apache.maven.api.di.Singleton @Singleton}</li> 40 * <li>{@link org.apache.maven.api.di.SessionScoped @SessionScoped}</li> 41 * <li>{@link org.apache.maven.api.di.MojoExecutionScoped @MojoExecutionScoped}</li> 42 * </ul> 43 * 44 * @since 4.0.0 45 */ 46 @Experimental 47 public interface Scope { 48 49 @Nonnull 50 <T> Supplier<T> scope(@Nonnull Key<T> key, @Nonnull Supplier<T> unscoped); 51 }