ABP 框架第一篇 ABP框架入门
1、下载ABP框架,https://aspnetboilerplate.com/,选择Vue版本
2、AbpBootstrapper ABP启动类,负责注册组件,里面包含:
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容器中,方便后面使用
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框架,
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();
});
}
// 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;
}
}
注册所有组件
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());
修改数据库地址跑起来
posted on 2022-01-11 17:57 topguntopgun 阅读(793) 评论(0) 收藏 举报
浙公网安备 33010602011771号