Abp Application級(jí)別的生命周期
本篇級(jí)別: 中高級(jí)篇,假設(shè)各位知道Abp是什么, Abp里面的基本的概念及用法(想了解基本概念的可在這里學(xué)習(xí): http://www.rzrgm.cn/mienreal/p/4358806.html)
AbpWebApplication
AbpWebApplication是需要我們的Global.cs里面的HttpApplication繼承他, 初始化分兩個(gè)階段
構(gòu)造方法AbpWebApplication()
在這個(gè)方法里面,做了非常重要但是很簡(jiǎn)單的事, 通過(guò) AbpBootstrapper類庫(kù),間接實(shí)例化了IocManager.Instance, 并且注冊(cè)了IocManager,IIlocManager,IIocRegistrar, IIocResolver做了注冊(cè),
也就是這一步完成之后,IocManager.Instance.Reslove只能解析上面的四個(gè)類型, 其他類型到目前為止,還一個(gè)都沒(méi)有注冊(cè).
Application_Start(object sender, EventArgs e)方法
a. 注冊(cè)了IAssemblyFinder, 關(guān)聯(lián)到了WebAssemblyFinder類庫(kù), 猜主要是用來(lái)尋找相關(guān)類庫(kù), 看其代碼主要是獲取當(dāng)前bin目錄下的所有dll組件,并跟當(dāng)前已加載的 Assembly做比較,最后返回當(dāng)前程序已加載的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()上面注冊(cè)的大部分都是配置類,最后四個(gè)有TypeFinder,ModuleFinder,ModuleManager, LocalizationManager.
Navigation: 導(dǎo)航相關(guān),不曉得干啥
LocalizationConfiguration, LocalizationManager, 多語(yǔ)言相關(guān),這個(gè)基本根據(jù)實(shí)際情況看。
Authorization: 授權(quán)相關(guān), 跟Authentication有區(qū)別,前者授權(quán),后者負(fù)責(zé)的呢登錄認(rèn)證
Feature: 不曉得干啥
Settings: 看起來(lái)是設(shè)置相關(guān)的
ModuleConfiguration: Abp模塊配置,這個(gè)看起來(lái)應(yīng)該很重要,畢竟是搞Module么,這個(gè)可是Abp的核心概念
EventBus: 事件總線,看程序規(guī)模跟復(fù)雜度了,不過(guò)是很好玩的概念
MultiTenancy: 多租戶概念,也看業(yè)務(wù)邏輯跟系統(tǒng)應(yīng)用場(chǎng)景了.
Caching: 緩存,必須得搞清楚的概念
Auditing: 審計(jì),這個(gè)設(shè)計(jì)的還是不錯(cuò),有很好的參考價(jià)值, 但是也有一些弊端,需要綜合考慮,感覺(jué)利大于弊。
AbpStartup: 管Abp啟動(dòng)階段的事,上述列的里面,這個(gè)是最先用到的,也是最先不用管的:)
TypeFinder: 類型查找的,
ModuleFinder, ModuleManager: 跟上面的ModuleConfiguration一樣,都是Module管理相關(guān)的
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項(xiàng)Configuration, 只是在b.2的介紹里面增加了UnitOfWork的Configuration
UnitOfWork: 工作單元, 這個(gè)概念現(xiàn)在很普遍,大家都應(yīng)該了解.
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對(duì)各個(gè)Module排序
3. 一次按照PreInit, Init,PostInit的順序一次執(zhí)行.
Application_End(object sender, EventArgs e)方法
Module Shutdown
var sortedModules = _modules.GetSortedModuleListByDependency(); sortedModules.Reverse(); sortedModules.ForEach(sm => sm.Instance.Shutdown());這部分很簡(jiǎn)單,就是通過(guò)各個(gè)Module的Shutdown釋放各個(gè)Module的資源
浙公網(wǎng)安備 33010602011771號(hào)