本篇級別: 中高級篇,假設各位知道Abp是什么, Abp里面的基本的概念及用法(想了解基本概念的可在這里學習: http://www.49028c.com/mienreal/p/4358806.html)
AbpWebApplication是需要我們的Global.cs里面的HttpApplication繼承他, 初始化分兩個階段
在這個方法里面,做了非常重要但是很簡單的事, 通過 AbpBootstrapper類庫,間接實例化了IocManager.Instance, 并且注冊了IocManager,IIlocManager,IIocRegistrar, IIocResolver做了注冊,
也就是這一步完成之后,IocManager.Instance.Reslove只能解析上面的四個類型, 其他類型到目前為止,還一個都沒有注冊.
a. 注冊了IAssemblyFinder, 關聯到了WebAssemblyFinder類庫, 猜主要是用來尋找相關類庫, 看其代碼主要是獲取當前bin目錄下的所有dll組件,并跟當前已加載的 Assembly做比較,最后返回當前程序已加載的dll, 忽略未加載的.
b. AbpBootstrapper初始化,
b.1 IocManager.IocContainer.Install(new AbpCoreInstaller());
Component.For<IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>().ImplementedBy<UnitOfWorkDefaultOptions>().LifestyleSingleton(), Component.For<INavigationConfiguration, NavigationConfiguration>().ImplementedBy<NavigationConfiguration>().LifestyleSingleton(), Component.For<ILocalizationConfiguration, LocalizationConfiguration>().ImplementedBy<LocalizationConfiguration>().LifestyleSingleton(), Component.For<IAuthorizationConfiguration, AuthorizationConfiguration>().ImplementedBy<AuthorizationConfiguration>().LifestyleSingleton(), Component.For<IFeatureConfiguration, FeatureConfiguration>().ImplementedBy<FeatureConfiguration>().LifestyleSingleton(), Component.For<ISettingsConfiguration, SettingsConfiguration>().ImplementedBy<SettingsConfiguration>().LifestyleSingleton(), Component.For<IModuleConfigurations, ModuleConfigurations>().ImplementedBy<ModuleConfigurations>().LifestyleSingleton(), Component.For<IEventBusConfiguration, EventBusConfiguration>().ImplementedBy<EventBusConfiguration>().LifestyleSingleton(), Component.For<IMultiTenancyConfig, MultiTenancyConfig>().ImplementedBy<MultiTenancyConfig>().LifestyleSingleton(), Component.For<ICachingConfiguration, CachingConfiguration>().ImplementedBy<CachingConfiguration>().LifestyleSingleton(), Component.For<IAuditingConfiguration, AuditingConfiguration>().ImplementedBy<AuditingConfiguration>().LifestyleSingleton(), Component.For<IAbpStartupConfiguration, AbpStartupConfiguration>().ImplementedBy<AbpStartupConfiguration>().LifestyleSingleton(), Component.For<ITypeFinder>().ImplementedBy<TypeFinder>().LifestyleSingleton(), Component.For<IModuleFinder>().ImplementedBy<DefaultModuleFinder>().LifestyleTransient(), Component.For<IAbpModuleManager>().ImplementedBy<AbpModuleManager>().LifestyleSingleton(), Component.For<ILocalizationManager, LocalizationManager>().ImplementedBy<LocalizationManager>().LifestyleSingleton()上面注冊的大部分都是配置類,最后四個有TypeFinder,ModuleFinder,ModuleManager, LocalizationManager.
Navigation: 導航相關,不曉得干啥
LocalizationConfiguration, LocalizationManager, 多語言相關,這個基本根據實際情況看。
Authorization: 授權相關, 跟Authentication有區別,前者授權,后者負責的呢登錄認證
Feature: 不曉得干啥
Settings: 看起來是設置相關的
ModuleConfiguration: Abp模塊配置,這個看起來應該很重要,畢竟是搞Module么,這個可是Abp的核心概念
EventBus: 事件總線,看程序規模跟復雜度了,不過是很好玩的概念
MultiTenancy: 多租戶概念,也看業務邏輯跟系統應用場景了.
Caching: 緩存,必須得搞清楚的概念
Auditing: 審計,這個設計的還是不錯,有很好的參考價值, 但是也有一些弊端,需要綜合考慮,感覺利大于弊。
AbpStartup: 管Abp啟動階段的事,上述列的里面,這個是最先用到的,也是最先不用管的:)
TypeFinder: 類型查找的,
ModuleFinder, ModuleManager: 跟上面的ModuleConfiguration一樣,都是Module管理相關的
b.2 IocManager.Resolve<AbpStartupConfiguration>().Initialize();
Localization = IocManager.Resolve<ILocalizationConfiguration>();Modules = IocManager.Resolve<IModuleConfigurations>();Features = IocManager.Resolve<IFeatureConfiguration>();Navigation = IocManager.Resolve<INavigationConfiguration>();Authorization = IocManager.Resolve<IAuthorizationConfiguration>();Settings = IocManager.Resolve<ISettingsConfiguration>();UnitOfWork = IocManager.Resolve<IUnitOfWorkDefaultOptions>();EventBus = IocManager.Resolve<IEventBusConfiguration>();MultiTenancy = IocManager.Resolve<IMultiTenancyConfig>();Auditing = IocManager.Resolve<IAuditingConfiguration>();Caching = IocManager.Resolve<ICachingConfiguration>();一共11項Configuration, 只是在b.2的介紹里面增加了UnitOfWork的Configuration
UnitOfWork: 工作單元, 這個概念現在很普遍,大家都應該了解.
b.3 _moduleManager.InitializeModules();
public virtual void InitializeModules(){ LoadAll(); var sortedModules = _modules.GetSortedModuleListByDependency(); sortedModules.ForEach(module => module.Instance.PReInitialize()); sortedModules.ForEach(module => module.Instance.Initialize()); sortedModules.ForEach(module => module.Instance.PostInitialize());}1. 加載所有Module
2. 按照DepondsOnAttribute對各個Module排序
3. 一次按照PreInit, Init,PostInit的順序一次執行.
Module Shutdown
var sortedModules = _modules.GetSortedModuleListByDependency();sortedModules.Reverse();sortedModules.ForEach(sm => sm.Instance.Shutdown());這部分很簡單,就是通過各個Module的Shutdown釋放各個Module的資源
新聞熱點
疑難解答