collado-mike commented on code in PR #493:
URL: https://github.com/apache/polaris/pull/493#discussion_r1868485544


##########
polaris-service/src/main/java/org/apache/polaris/service/context/RealmScopeContext.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.polaris.service.context;
+
+import jakarta.inject.Singleton;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.context.RealmScope;
+import org.glassfish.hk2.api.ActiveDescriptor;
+import org.glassfish.hk2.api.Context;
+import org.glassfish.hk2.api.ServiceHandle;
+
+@Singleton
+public class RealmScopeContext implements Context<RealmScope> {
+  private final Map<String, Map<ActiveDescriptor<?>, Object>> contexts = new 
ConcurrentHashMap<>();
+
+  @Override
+  public Class<? extends Annotation> getScope() {
+    return RealmScope.class;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <U> U findOrCreate(ActiveDescriptor<U> activeDescriptor, 
ServiceHandle<?> root) {

Review Comment:
   I'd worry that the intention was not clear - readers would just have to know 
that an item annotated with `@RequestScoped` could actually live beyond the 
scope of a single request. In fact, they could be used by multiple concurrent 
requests, while the `@RequestScoped` annotation would convey that it's safe for 
an object to mutate state possibly leading to thread safety errors. I think all 
of the CDI providers offer support for custom scopes and it doesn't seem like a 
lot of work for what amounts to (IMO) clear intentions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to