[
https://issues.apache.org/jira/browse/MNG-7954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17810969#comment-17810969
]
ASF GitHub Bot commented on MNG-7954:
-------------------------------------
gnodet commented on code in PR #1393:
URL: https://github.com/apache/maven/pull/1393#discussion_r1466629617
##########
maven-di/src/main/java/org/apache/maven/di/Injector.java:
##########
@@ -0,0 +1,613 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.di;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import java.util.function.Supplier;
+import java.util.function.UnaryOperator;
+
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.di.binding.*;
+import org.apache.maven.di.impl.CompiledBinding;
+import org.apache.maven.di.impl.CompiledBindingLocator;
+import org.apache.maven.di.impl.Preprocessor;
+import org.apache.maven.di.module.Module;
+import org.apache.maven.di.module.Modules;
+import org.apache.maven.di.util.Trie;
+import org.apache.maven.di.util.Utils;
+
+import static java.util.stream.Collectors.toMap;
+import static org.apache.maven.di.Scope.UNSCOPED;
+import static org.apache.maven.di.util.Types.parameterizedType;
+
+/**
+ * Injector is the main working component of the ActiveJ Inject.
+ * <p>
+ * It stores a trie of binding graphs and a cache of already made singletons.
+ * <p>
+ * Each injector is associated with exactly zero or one instance per {@link
Key}.
+ * <p>
+ * Injector uses binding graph at the root of the trie to recursively create
and then store instances of objects
+ * associated with some {@link Key keys}.
+ * Branches of the trie are used to {@link #enterScope enter scopes}.
+ */
+@SuppressWarnings({"unused", "WeakerAccess", "rawtypes"})
+public final class Injector implements ResourceLocator {
+ static class ScopeLocalData {
+ final Scope[] scope;
+ final Map<Key<?>, Binding<?>> bindings;
+ final Map<Key<?>, CompiledBinding<?>> compiledBindings;
+ final Map<Key<?>, Integer> slotMapping;
+ final int slots;
+ final CompiledBinding<?>[] eagerSingletons;
+
+ ScopeLocalData(
+ Scope[] scope,
+ Map<Key<?>, Binding<?>> bindings,
+ Map<Key<?>, CompiledBinding<?>> compiledBindings,
+ Map<Key<?>, Integer> slotMapping,
+ int slots,
+ CompiledBinding<?>[] eagerSingletons) {
+ this.scope = scope;
+ this.bindings = bindings;
+ this.compiledBindings = compiledBindings;
+ this.slotMapping = slotMapping;
+ this.slots = slots;
+ this.eagerSingletons = eagerSingletons;
+ }
+ }
+
+ final @Nullable Injector parent;
+ final Trie<Scope, ScopeLocalData> scopeDataTree;
+
+ final Map<Key<?>, Integer> localSlotMapping;
+ final Map<Key<?>, CompiledBinding<?>> localCompiledBindings;
+
+ final AtomicReferenceArray[] scopeCaches;
+
+ private static Supplier<UnaryOperator<CompiledBinding<?>>>
bytecodePostprocessorFactory = UnaryOperator::identity;
+
+ /**
+ * Enables specialization of compiled bindings. <b>Depends on {@code
ActiveJ-Specializer} module</b>
+ */
+ @SuppressWarnings("unchecked")
+ public static void useSpecializer() {
Review Comment:
I don't think we need, so that will be removed.
> Provide a cleaner DI api
> ------------------------
>
> Key: MNG-7954
> URL: https://issues.apache.org/jira/browse/MNG-7954
> Project: Maven
> Issue Type: New Feature
> Components: API
> Reporter: Guillaume Nodet
> Priority: Major
> Fix For: 4.0.0
>
>
> With https://issues.apache.org/jira/browse/MNG-7947 the {{jakarta.inject}}
> package has been brought into the API.
> We need a cleaner way and not depend on any third party library if possible.
> The
> [{{SessionScope}}|https://github.com/apache/maven/blob/23bca281fcd084ac21d80f5a2950dcee30a19080/maven-core/src/main/java/org/apache/maven/session/scope/internal/SessionScope.java#L123-L125]
> would also require some cleaning to avoid having to rely on
> {{{}(org.eclipse.sisu|javax.enterprise.inject|jakarta.enterprise.inject).Typed{}}}.
> For complete DI, we may also miss the sisu annotations
> ({{{}PostConstruct{}}}, {{PreDestroy}} and {{Priority}} and
> {{{}EagerSingleton{}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)