星空网 > 软件开发 > ASP.net

ABP框架详解(一)ABPBootstrapper

在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。

 




原标题:ABP框架详解(一)ABPBootstrapper

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

疫情期间多平台倒闭,Lazada季度订单却同比增长超100%:https://www.goluckyvip.com/news/3557.html
泰嘉物流:https://www.goluckyvip.com/news/3558.html
干货满满丨Shopee的品牌商城是什么?:https://www.goluckyvip.com/news/3559.html
亚马逊美国站关闭部分仓库 / 亚马逊某家居大卖获42429万投资:https://www.goluckyvip.com/news/356.html
Shopee与Lazada本土跨境的分水岭开始了:https://www.goluckyvip.com/news/3560.html
外媒:微软被拒,甲骨文或成TikTok在美业务“接盘手”:https://www.goluckyvip.com/news/3561.html
南京浦口都有什么好玩的地方 南京浦口都有什么好玩的地方推荐:https://www.vstour.cn/a/363180.html
永康白云风景区怎么走 白云山风景区怎么去??:https://www.vstour.cn/a/363181.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流