wangzhenxyz1 commented on a change in pull request #9187:
URL: https://github.com/apache/dubbo/pull/9187#discussion_r791517671



##########
File path: 
dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
##########
@@ -707,35 +708,58 @@ private T injectExtension(T instance) {
                 if (!isSetter(method)) {
                     continue;
                 }
-                /**
-                 * Check {@link DisableInject} to see if we need auto 
injection for this property
+
+                /*
+                 * Check {@link DisableInject} to see if we need autowire 
injection for this property
                  */
                 if (method.getAnnotation(DisableInject.class) != null) {
                     continue;
                 }
+
                 Class<?> pt = method.getParameterTypes()[0];
                 if (ReflectUtils.isPrimitives(pt)) {
                     continue;
                 }
 
-                try {
-                    String property = getSetterProperty(method);
-                    Object object = objectFactory.getExtension(pt, property);
-                    if (object != null) {
-                        method.invoke(instance, object);
+                /*
+                 * Check {@link Inject} to see if we need auto-injection for 
this property
+                 * {@link Inject#enable} == false will skip inject property 
phase
+                 * {@link Inject#InjectType#ByName} default inject by name
+                 */
+                String property = getSetterProperty(method);
+                Inject inject = method.getAnnotation(Inject.class);

Review comment:
       About injection if miss annotation, this is default injection logic, i 
have not changed that.
   Default injection behavior is injection by name with setter property name.
   Right now Injection logic code is compatible with legacy code, as well as it 
supports injection by type features.

##########
File path: 
dubbo-common/src/main/java/org/apache/dubbo/common/extension/Inject.java
##########
@@ -22,8 +22,20 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import static org.apache.dubbo.common.extension.Inject.InjectType.ByName;
+
 @Documented
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.TYPE, ElementType.METHOD})
-public @interface DisableInject {
+public @interface Inject {
+    // whether enable injection or not
+    boolean enable() default true;
+
+    // inject type default by name injection
+    InjectType type() default ByName;
+
+    enum InjectType{
+        ByName,
+        ByType
+    }

Review comment:
       First of all all ut&it pass, then this pr is compatible with legacy 
code, 
   I think break implementation do not exist!




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to