Loading

一张图看懂 OrchardCore 中的模块加载及依赖管理

先上图

 

  

Manifest.cs   

Module 与 Feature

Module 特性  如果模块中只有一个 功能【Feature】 那么可以直接用 Module 替代,也就是

    /// <summary>
    /// Defines a Module which is composed of features. If the Module has only one default
    /// feature, it may be defined there.
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
    public class ModuleAttribute : FeatureAttribute

 

Feature 特性  ,只要 存在任何明确定义的  Feature 特性,那么  Module 的默认 Feature 功能将被忽略

  /// <summary>
    /// Defines a Feature in a Module, can be used multiple times.
    /// If at least one Feature is defined, the Module default feature is ignored.
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
    public class FeatureAttribute : Attribute

 

Module 中的 默认Feature 和 Feature 两个特性 的应用类似于 类型的 构造函数

如果 Module 中未明确定义 任何 Feature ,那么将根据 模块程序集名称自动 构建一个 默认Feature

如果明确定义了任何  Feature 特性,则 默认 Feature 不再生效

Dependencies 

在功能管理界面,如果启用了该功能,将会自动启用该模块依赖的功能

 

Startup  中的 RequireFeatures  与 Feature

RequireFeatures  

参数为依赖的功能ID 清单,如果列出的功能都已加载完成,则将开始执行此 Startup

Feature

与 Manifest 中的 Feature.Id 或 Module.Id 对应  , 如果启用了此功能,则将执行下面的 代码

 

posted @ 2022-08-19 12:21  韩严重  阅读(151)  评论(0编辑  收藏  举报