星空网 > 软件开发 > 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 (#换成@)。

TikTok Shop黑五爆卖8000单?Forever 21上线Shein!:https://www.goluckyvip.com/news/32068.html
Lazada印尼站双十一战报:家居、美容个护类别斩获佳绩:https://www.goluckyvip.com/news/32069.html
美国暴乱,快递哄抢, 物流问题、售后纠纷如何处理?:https://www.goluckyvip.com/news/3207.html
“反向海淘”火爆,香港快递升级:https://www.goluckyvip.com/news/32070.html
TikTok Shop黑五爆卖8000单?Forever 21上线Shein!| 电商123:https://www.goluckyvip.com/news/32071.html
比亚马逊慢一步发展物流,TikTok能攻下美国市场吗?:https://www.goluckyvip.com/news/32072.html
深圳有没有比较好玩的景点 深圳有没有比较好玩的景点推荐一下:https://www.vstour.cn/a/366175.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流