欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET Core Zero模塊系統(tǒng)講解

 更新時間:2022年02月15日 10:32:21   作者:痕跡g  
本文詳細講解了ASP.NET Core Zero模塊系統(tǒng),對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

簡介

在ABP中, 模板的定義就是一個類, 只需要繼承 AbpModule, 該類可以通過nuget包搜索 ABP 安裝。

下面演示在應用程序或類庫中, 定義一個模塊:

 public class ApplicationModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(ApplicationModule).GetAssembly());
        }
    }

說明: 關(guān)于IocManager.RegisterAssemblyByConvention的作用, 則是將當前程序集模塊注冊到容器當中, 作為一個模塊, 常見的是暴露模塊對應的服務,
而其中所有的服務, 都是按照聲明周期而聲明, 例如: ITransientDependency ,ISingletonDependency。

下面展示了IocManager.RegisterAssemblyByConvention 執(zhí)行的部分細節(jié):

public void RegisterAssembly(IConventionalRegistrationContext context)
{
            //Transient
            context.IocManager.IocContainer.Register(
                Classes.FromAssembly(context.Assembly)
                    .IncludeNonPublicTypes()
                    .BasedOn<ITransientDependency>()
                    .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
                    .WithService.Self()
                    .WithService.DefaultInterfaces()
                    .LifestyleTransient()
                );

            //Singleton
            context.IocManager.IocContainer.Register(
                Classes.FromAssembly(context.Assembly)
                    .IncludeNonPublicTypes()
                    .BasedOn<ISingletonDependency>()
                    .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
                    .WithService.Self()
                    .WithService.DefaultInterfaces()
                    .LifestyleSingleton()
                );

            //...
}

常見的方法

在AbpModule中, 定義了幾組方法, 分別在應用程序模塊加載的前后進行, 如下:

        public virtual void Initialize();
        public virtual void PostInitialize();
        public virtual void PreInitialize();
        public virtual void Shutdown();
  • Initialize : 通常, 這里用于注冊程序集依賴選項
  • PostInitialize : 初始化最后調(diào)用
  • PreInitialize : 初始化之前調(diào)用
  • Shutdown : 當應用程序關(guān)閉時調(diào)用

模塊依賴

通常來講, 一個模塊往往依賴與一個或者多個模塊, 這里, 也涉及到了模塊的加載生命周期。
假設(shè): 模塊A依賴于模塊B, 那么意味著模塊B會先于模塊A初始化。

關(guān)于模塊之間的依賴, 則可以通過特性的方式 DependsOn 為模塊顯示聲明, 如下所示:

[DependsOn(typeof(BModule))]
public class AModule : AbpModule
{
    public override void Initialize()
    {
        //...
    }
}

模塊加載

任何模塊都依賴于啟動模塊進行加載, 這很常見, 例如機箱中的各個模塊: 內(nèi)存、硬盤、顯卡、電源。 都需要通電的過程, 讓他們進行整個啟動過程。
Abp 則依賴于 AbpBootstrapper 來進行調(diào)用初始化, 可以通過 Initialize 方法加載。

 public static class ApplicationBootstrapper
    {
        public static AbpBootstrapper AbpBootstrapper { get; private set; }

       public static void Init(){
         //...
         AbpBootstrapper.Initialize();
       }
    }

同樣, 模塊也可以讀取指定文件夾路徑的方式進行加載模塊, 如下所示:

services.AddAbp<MyStartupModule>(options =>
{
    options.PlugInSources.Add(new FolderPlugInSource(@"C:\MyPlugIns"));
});

or

services.AddAbp<MyStartupModule>(options =>
{
    options.PlugInSources.AddFolder(@"C:\MyPlugIns");
});

查看更多

到此這篇關(guān)于ASP.NET Core Zero模塊系統(tǒng)的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論