ABP框架详解(一)ABPBootstrapper
2024-09-25 15:28:58
在ABP框架的AbpBootstrapper主要用于框架的基本配置的注册和初始化,在Web应用启动阶段实例化一个AbpBootstrapper并调用Initialize方法初始化,该类主要包含两个公有属性分别是IIocManager和IAbpModuleManager
- IIocManager内部包装了一个Castle的依赖注入容器IWindsorContainer,所有类型的注册,解析还有后面实现的AOP机制的拦截器都是注册在该容器中的,将具体的注册还有解析功能分别包含在其父接口IIocRegistrar和IIocResolver中,其中AddConventionalRegistrar,RegisterAssemblyByConvention(Assembly assembly),RegisterAssemblyByConvention(Assembly assembly, ConventionalRegistrationConfig config)三个方法需要特别注意,第一个方法,是向IocManager的一个私有泛型集合List<IConventionalDependencyRegistrar>注册注册机制,通常所有的Module类的预初始化方法中调用以决定哪些类型需要被注册(如果没有就无需调用),比如在Abp程序集中的BasicConventionalRegistrar实现的就是搜索并注册指定的程序集中的所有实现了ITransientDependency,ISingletonDependency和IInterceptor的类并注册到依赖容器中,第二,第三个方法执行真正的注册逻辑,通常在一个个具体的Module的初始化方法中调用,传入当前Module所属的程序集,迭代List<IConventionalDependencyRegistrar>将当前程序集作为参数执行注册,第二,第三个方法的区别在于第三个方法多了一个ConventionalRegistrationConfig参数,以决定是否还需要搜索当前程序及中的IWindsorInstaller的实现类进行注册,默认是需要的。
- IAbpModuleManager主要用于管理所有的模块默认也就是一个个的程序集(一个模块对应一个程序集),主要用于搜索到所有的Module以及他们的依赖Module,首先执行所有Module的PreInitialize方法再执行所有的Initialize,最后执行所有的PostInitialize,执行IAbpModuleManager的ShutdownModules时顺序颠倒依次执行所有具体Module的ShutDown方法。
1.在执行AbpBootstrapper的Initialize()方法时首先会执行
IocManager.IocContainer.Install(new AbpCoreInstaller());
来注册系统框架级的所有配置类,具体代码如下
internal class AbpCoreInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
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()
);
}
}
2.接着解析AbpStartupConfiguration的实例调用其Initialize()来完成所有配置项的初始设值。
3.解析IAbpModuleManager的实例调用其InitializeModules()初始化所有的Module
在AbpBootstrapper的Dispose方法中析构IAbpModuleManager,执行其ShutdownModules,关闭所有Module。
最新文章
- LINUX 文件权限详解
- ChartServices Dev图形封装
- Git 的origin和master分析
- float属性
- jQuery 工具类库集锦
- 解决Cannot find or open the PDB file问题
- C++判断五位以内的对称素数
- uva 1378 A Funny Stone Game (博弈-SG)
- 远程安装实施时,如何配置远程服务器的本地 yum 安装源
- Hibernate介绍和入门案例
- 大数据 -->; 大数据关键技术
- 完全关闭Hyper-v的方法
- httpservlet里单纯分页
- VS code 代码格式整理的配置
- html图片上传阅览并且点击放大
- Dash VS Underscore
- MR架构
- es6 学习二 Generator
- Alpha阶段敏捷冲刺(八)
- 图片压缩-KMeans
热门文章
- 将搜狗词库.scel格式转化为.txt格式
- python获取命令行变量
- android Handler机制详解
- Sharepoint创建List
- 强大的Spring缓存技术(中)
- 【SQLServer】“无法对数据库’XXX’ 执行删除,因为它正用于复制”的解决方法
- handsontable组件和jqwidgets(jqxdragdrop组件)在一个页面产生调整宽高bug
- CAD 二次开发----- 块(一)
- 为什么LTE系统的最小时间单位是Ts?
- PerconaXtraBackup 压缩备份集