ABP 框架第一篇 ABP框架入门
1、下载ABP框架,https://aspnetboilerplate.com/,选择Vue版本
2、AbpBootstrapper ABP启动类,负责注册组件,里面包含:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | private AbpModuleManager _moduleManager; private ILogger _logger; // // 摘要: // Get the startup module of the application which depends on other used modules. public Type StartupModule { get ; } // // 摘要: // A list of plug in folders. public PlugInSourceList PlugInSources { get ; } // // 摘要: // Gets IIocManager object used by this class. public IIocManager IocManager { get ; } |
根据启动模块创建ABPBootstrapper对象,并且注入到DI容器中,方便后面使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | private AbpBootstrapper(Type startupModule, Action<AbpBootstrapperOptions> optionsAction = null ) { Check.NotNull(startupModule, "startupModule" ); AbpBootstrapperOptions abpBootstrapperOptions = new AbpBootstrapperOptions(); optionsAction?.Invoke(abpBootstrapperOptions); if (! typeof (AbpModule).GetTypeInfo().IsAssignableFrom(startupModule)) { throw new ArgumentException( "startupModule should be derived from AbpModule." ); } StartupModule = startupModule; IocManager = abpBootstrapperOptions.IocManager; PlugInSources = abpBootstrapperOptions.PlugInSources; _logger = NullLogger.Instance; AddInterceptorRegistrars(abpBootstrapperOptions.InterceptorOptions); } |
private static AbpBootstrapper AddAbpBootstrapper<TStartupModule>(IServiceCollection services, Action<AbpBootstrapperOptions> optionsAction) where TStartupModule : AbpModule
{
AbpBootstrapper abpBootstrapper = AbpBootstrapper.Create<TStartupModule>(optionsAction);
services.AddSingleton(abpBootstrapper);
return abpBootstrapper;
}
初始化ABP框架,
1 2 3 4 5 6 7 8 9 10 | private static void InitializeAbp(IApplicationBuilder app) { AbpBootstrapper abpBootstrapper = app.ApplicationServices.GetRequiredService<AbpBootstrapper>(); abpBootstrapper.Initialize(); IHostApplicationLifetime service = app.ApplicationServices.GetService<IHostApplicationLifetime>(); service.ApplicationStopping.Register( delegate { abpBootstrapper.Dispose(); }); }<br><br> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // Initializes the ABP system. public virtual void Initialize() { ResolveLogger(); try { RegisterBootstrapper(); IocManager.IocContainer.Install( new AbpCoreInstaller()); IocManager.Resolve<AbpPlugInManager>().PlugInSources.AddRange(PlugInSources); IocManager.Resolve<AbpStartupConfiguration>().Initialize(); _moduleManager = IocManager.Resolve<AbpModuleManager>(); _moduleManager.Initialize(StartupModule); _moduleManager.StartModules(); 执行所有模块的方法 } catch (Exception ex) { _logger.Fatal(ex.ToString(), ex); throw ; } } |
注册所有组件
1 2 | container.Register(Component.For<IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>().ImplementedBy<UnitOfWorkDefaultOptions>().LifestyleSingleton(), Component.For<IAbpValidationDefaultOptions, AbpValidationDefaultOptions>().ImplementedBy<AbpValidationDefaultOptions>().LifestyleSingleton(), Component.For<IAbpAuditingDefaultOptions, AbpAuditingDefaultOptions>().ImplementedBy<AbpAuditingDefaultOptions>().LifestyleSingleton(), Component.For<INavigationConfiguration, NavigationConfiguration>().ImplementedBy<NavigationConfiguration>().LifestyleSingleton(), Component.For<ILocalizationConfiguration, LocalizationConfiguration>().ImplementedBy<LocalizationConfiguration>().LifestyleSingleton(), Component.For<IAuthorizationConfiguration, AuthorizationConfiguration>().ImplementedBy<AuthorizationConfiguration>().LifestyleSingleton(), Component.For<IValidationConfiguration, ValidationConfiguration>().ImplementedBy<ValidationConfiguration>().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<IBackgroundJobConfiguration, BackgroundJobConfiguration>().ImplementedBy<BackgroundJobConfiguration>().LifestyleSingleton(), Component.For<INotificationConfiguration, NotificationConfiguration>().ImplementedBy<NotificationConfiguration>().LifestyleSingleton(), Component.For<IEmbeddedResourcesConfiguration, EmbeddedResourcesConfiguration>().ImplementedBy<EmbeddedResourcesConfiguration>().LifestyleSingleton(), Component.For<IAbpStartupConfiguration, AbpStartupConfiguration>().ImplementedBy<AbpStartupConfiguration>().LifestyleSingleton(), Component.For<IEntityHistoryConfiguration, EntityHistoryConfiguration>().ImplementedBy<EntityHistoryConfiguration>().LifestyleSingleton(), Component.For<ITypeFinder, TypeFinder>().ImplementedBy<TypeFinder>().LifestyleSingleton(), Component.For<IAbpPlugInManager, AbpPlugInManager>().ImplementedBy<AbpPlugInManager>().LifestyleSingleton(), Component.For<IAbpModuleManager, AbpModuleManager>().ImplementedBy<AbpModuleManager>().LifestyleSingleton(), Component.For<IAssemblyFinder, AbpAssemblyFinder>().ImplementedBy<AbpAssemblyFinder>().LifestyleSingleton(), Component.For<ILocalizationManager, LocalizationManager>().ImplementedBy<LocalizationManager>().LifestyleSingleton(), Component.For<IWebhooksConfiguration, WebhooksConfiguration>().ImplementedBy<WebhooksConfiguration>().LifestyleSingleton(), Component.For<IDynamicEntityPropertyDefinitionContext, DynamicEntityPropertyDefinitionContext>().ImplementedBy<DynamicEntityPropertyDefinitionContext>().LifestyleTransient(), Component.For<IDynamicEntityPropertyConfiguration, DynamicEntityPropertyConfiguration>().ImplementedBy<DynamicEntityPropertyConfiguration>().LifestyleSingleton()); |
修改数据库地址跑起来
分类:
ABP 开源框架
posted on 2022-01-11 17:57 topguntopgun 阅读(737) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?