一張圖看懂 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 對應  , 如果啓用了此功能,則將執行下面的 代碼

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章