You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ky...@apache.org on 2021/08/30 06:29:34 UTC
[dubbo] 02/03: Improve scope model aware
This is an automated email from the ASF dual-hosted git repository.
kylixs pushed a commit to branch 3.0-multi-instances
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 71b15e0c6b08aa431c994727b73b749ca1e815df
Author: gongdewei <ky...@qq.com>
AuthorDate: Mon Aug 30 12:47:54 2021 +0800
Improve scope model aware
---
.../model/ScopeModelAwareExtensionProcessor.java | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessor.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessor.java
index 4c47c22..7ae6e5f 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessor.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessor.java
@@ -33,9 +33,24 @@ public class ScopeModelAwareExtensionProcessor implements ExtensionPostProcessor
if (inited) {
return;
}
- frameworkModel = ScopeModelUtil.getFrameworkModel(scopeModel);
- applicationModel = ScopeModelUtil.getApplicationModel(scopeModel);
- moduleModel = ScopeModelUtil.getModuleModel(scopeModel);
+
+ // NOTE: Do not use ScopeModelUtil.getXxxModel() here, because cannot create a new model or use the default application/module model here.
+ // Only the visible and only matching scope model can be injected, that is, module -> application -> framework.
+ // The converse is a one-to-many relationship and cannot be injected.
+ // One framework may have multiple applications, and one application may have multiple modules.
+ // So, the spi extension/bean of application scope can be injected it's application model and framework model,
+ // but the spi extension/bean of framework scope cannot be injected an application or module model.
+
+ if (scopeModel instanceof FrameworkModel) {
+ frameworkModel = (FrameworkModel) scopeModel;
+ } else if (scopeModel instanceof ApplicationModel) {
+ applicationModel = (ApplicationModel) scopeModel;
+ frameworkModel = applicationModel.getFrameworkModel();
+ } else if (scopeModel instanceof ModuleModel) {
+ moduleModel = (ModuleModel) scopeModel;
+ applicationModel = moduleModel.getApplicationModel();
+ frameworkModel = applicationModel.getFrameworkModel();
+ }
inited = true;
}