亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

簡(jiǎn)介

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

下面演示在應(yīng)用程序或類庫(kù)中, 定義一個(gè)模塊:

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

說(shuō)明: 關(guān)于IocManager.RegisterAssemblyByConvention的作用, 則是將當(dāng)前程序集模塊注冊(cè)到容器當(dāng)中, 作為一個(gè)模塊, 常見(jiàn)的是暴露模塊對(duì)應(yīng)的服務(wù),
而其中所有的服務(wù), 都是按照聲明周期而聲明, 例如: ITransientDependency ,ISingletonDependency。

下面展示了IocManager.RegisterAssemblyByConvention 執(zhí)行的部分細(xì)節(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()
                );

            //...
}

常見(jiàn)的方法

在AbpModule中, 定義了幾組方法, 分別在應(yīng)用程序模塊加載的前后進(jìn)行, 如下:

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

模塊依賴

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

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

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

模塊加載

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

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

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

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

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)的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論