key);
}
diff --git a/maven-di/src/main/java/org/apache/maven/di/Key.java b/maven-di/src/main/java/org/apache/maven/di/Key.java
index 3e922bf0a4f5..6f13be353107 100644
--- a/maven-di/src/main/java/org/apache/maven/di/Key.java
+++ b/maven-di/src/main/java/org/apache/maven/di/Key.java
@@ -31,7 +31,7 @@
* The key defines an identity of a binding. In any DI, a key is usually a type of the object along
* with some optional tag to distinguish between bindings which make objects of the same type.
*
- * In ActiveJ Inject, a key is also a type token - special abstract class that can store type information
+ * In Maven Inject, a key is also a type token - special abstract class that can store type information
* with the shortest syntax possible in Java.
*
* For example, to create a key of type Map<String, List<Integer>>, you can just use
diff --git a/maven-di/src/main/java/org/apache/maven/di/Scope.java b/maven-di/src/main/java/org/apache/maven/di/Scope.java
index c05334f319f2..5da978b64a8f 100644
--- a/maven-di/src/main/java/org/apache/maven/di/Scope.java
+++ b/maven-di/src/main/java/org/apache/maven/di/Scope.java
@@ -18,10 +18,34 @@
*/
package org.apache.maven.di;
-import java.lang.annotation.Annotation;
import java.util.function.Supplier;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+
+/**
+ * A {@code Scope} defines how visible instances are when managed by a {@link org.apache.maven.di.Injector}.
+ * Typically, instances are created with no scope, meaning they don’t retain any state from the
+ * framework’s perspective: the {@code Injector} generates the instance, injects it into the necessary class,
+ * and then immediately forgets it. By linking a scope to a specific binding, the created instance can be
+ * “remembered” and reused for future injections.
+ *
+ * Instances are associated to a given scope by means of a {@link org.apache.maven.api.di.Scope @Scope}
+ * annotation, usually put on another annotation. For example, the {@code @Singleton} annotation is used
+ * to indicate that a given binding should be scoped as a singleton.
+ *
+ * The following scopes are currently supported:
+ *
+ * - {@link org.apache.maven.api.di.Singleton @Singleton}
+ * - {@link org.apache.maven.api.di.SessionScoped @SessionScoped}
+ * - {@link org.apache.maven.api.di.MojoExecutionScoped @MojoExecutionScoped}
+ *
+ *
+ * @since 4.0.0
+ */
+@Experimental
public interface Scope {
- Supplier scope(Key key, Annotation scope, Supplier unscoped);
+ @Nonnull
+ Supplier scope(@Nonnull Key key, @Nonnull Supplier unscoped);
}
diff --git a/maven-di/src/main/java/org/apache/maven/di/impl/DIException.java b/maven-di/src/main/java/org/apache/maven/di/impl/DIException.java
index 4aca38c16e97..b5e39bbfe792 100644
--- a/maven-di/src/main/java/org/apache/maven/di/impl/DIException.java
+++ b/maven-di/src/main/java/org/apache/maven/di/impl/DIException.java
@@ -25,7 +25,7 @@
* (missing or cyclic dependencies, incorrect annotations etc.) or in runtime when
* you ask an {@link Injector} for an instance it does not have a {@link Binding binding} for.
*/
-public final class DIException extends RuntimeException {
+public class DIException extends RuntimeException {
public DIException(String message) {
super(message);
}
diff --git a/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java b/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java
index 1e047f55c211..34508ce18b20 100644
--- a/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java
+++ b/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java
@@ -241,7 +241,7 @@ protected Supplier compile(Binding binding) {
.orElseThrow(() -> new DIException("Scope not bound for annotation "
+ binding.getScope().annotationType()))
.get();
- compiled = scope.scope((Key) binding.getOriginalKey(), binding.getScope(), compiled);
+ compiled = scope.scope((Key) binding.getOriginalKey(), compiled);
}
return compiled;
}
@@ -379,8 +379,7 @@ private static class SingletonScope implements Scope {
@SuppressWarnings("unchecked")
@Override
- public java.util.function.Supplier scope(
- Key key, Annotation scope, java.util.function.Supplier unscoped) {
+ public java.util.function.Supplier scope(Key key, java.util.function.Supplier unscoped) {
return (java.util.function.Supplier)
cache.computeIfAbsent(key, k -> new java.util.function.Supplier() {
volatile T instance;