首页 技术 正文
技术 2022年11月17日
0 收藏 393 点赞 3,543 浏览 3439 个字

在ABP框架的AbpBootstrapper主要用于框架的基本配置的注册和初始化,在Web应用启动阶段实例化一个AbpBootstrapper并调用Initialize方法初始化,该类主要包含两个公有属性分别是IIocManager和IAbpModuleManager

  1. 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的实现类进行注册,默认是需要的。
  2. 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。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898