網站首頁 編程語言 正文
簡介
在ABP中, 模板的定義就是一個類, 只需要繼承 AbpModule, 該類可以通過nuget包搜索?ABP?安裝。
下面演示在應用程序或類庫中, 定義一個模塊:
public class ApplicationModule : AbpModule { public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(ApplicationModule).GetAssembly()); } }
說明: 關于IocManager.RegisterAssemblyByConvention的作用, 則是將當前程序集模塊注冊到容器當中, 作為一個模塊, 常見的是暴露模塊對應的服務,
而其中所有的服務, 都是按照聲明周期而聲明, 例如: ITransientDependency ,ISingletonDependency。
下面展示了IocManager.RegisterAssemblyByConvention 執行的部分細節:
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 : 初始化最后調用
- PreInitialize : 初始化之前調用
- Shutdown : 當應用程序關閉時調用
模塊依賴
通常來講, 一個模塊往往依賴與一個或者多個模塊, 這里, 也涉及到了模塊的加載生命周期。
假設: 模塊A依賴于模塊B, 那么意味著模塊B會先于模塊A初始化。
關于模塊之間的依賴, 則可以通過特性的方式 DependsOn 為模塊顯示聲明, 如下所示:
[DependsOn(typeof(BModule))] public class AModule : AbpModule { public override void Initialize() { //... } }
模塊加載
任何模塊都依賴于啟動模塊進行加載, 這很常見, 例如機箱中的各個模塊: 內存、硬盤、顯卡、電源。 都需要通電的過程, 讓他們進行整個啟動過程。
Abp 則依賴于 AbpBootstrapper 來進行調用初始化, 可以通過 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"); });
原文鏈接:https://www.cnblogs.com/zh7791/p/15502528.html
相關推薦
- 2023-04-19 C/C++實現內存泄漏檢測詳解_C 語言
- 2022-06-25 Python制作簡易計算器功能_python
- 2024-03-21 SpringBoot +MyBatis批量插入數據
- 2022-09-04 Python裝飾器有哪些絕妙的用法_python
- 2023-05-29 批標準化層?tf.keras.layers.Batchnormalization()解析_pytho
- 2022-03-19 使用Docker部署Spring?Boot項目的實現步驟_docker
- 2022-09-03 python四則運算表達式求值示例詳解_python
- 2023-03-02 sqlserver?合并列數據的實現_MsSql
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支