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());
    

  

修改数据库地址跑起来

 

posted on   topguntopgun  阅读(737)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

< 2025年3月 >
23 24 25 26 27 28 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 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示