GM tree abp modular development of 1: Basic use

I. Overview

Some functions are repeated in a single item or items, such as: accessories, the same system may use a plurality of modules that need different projects. Another example: There is a tree function, region, product classification, data dictionary, etc. unlimited class category. The most simple and crude way is to directly copy the code, and finally would have the same function is copied multiple copies, and each may eventually be modified beyond recognition.
The ideal approach is to encapsulate these common functions, through an iterative upgrade version, different projects can quote them, stay out of the package when the extension point to facilitate individual needs of each project

nuget search bxjg module can be found in the published source code follow-up will be put on github, hurry you can private me

Benpian explain how to use the next talk modularity provided by abp how to achieve a common tree module
Note: ASP.NET Boilerplate abbreviation abp, is Gesha please one hundred degrees

 

 

 

 

 

 

 

Second, how to use

For you to have an intuitive feel, let's look at how to use the module, follow revisit how to develop it.

2.1, the basic use

1, by nuget install a generic tree module (preferably all items are installed solution -> Right Management Solutions package once installed)

Install-Package BXJG.GeneralTree -Version 1.0.1


2, the configuration DbContext

public class ABPDbContext : AbpZeroDbContext<Tenant, Role, User>{
    //其它配置
    public virtual DbSet<GeneralTreeEntity> GeneralTrees { get; set; }

3、开启动动态webApi代理生成

public class ABPWebApiModule : AbpModule {
  public override void Initialize() {
    //other..
    Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
    .ForAll<IApplicationService>(typeof(GeneralTreeModule).Assembly, "gt/gt")
    .Build();


4、数据库迁移
add-migration addGeneralTree
update-database


此时编译调试,如果你有swaggerUI的话,应该可以看得到生成的动态webapi了

5、配置权限,在core项目的AuthorizationProvider中

public class ABPAuthorizationProvider : AuthorizationProvider{
  GeneralTreeModuleConfig cfg;//注入模块的配置对象
  public ABPAuthorizationProvider(GeneralTreeModuleConfig cfg) {
    this.cfg = cfg;
  }
  public override void SetPermissions(IPermissionDefinitionContext context){
    //其它权限的配置
    cfg.InitPermission(baseInfo);//通用字典权限的配置

 

6、配置菜单,配置方式跟权限配置类似。在web项目中的NavigationProvider

public class ABPNavigationProvider : NavigationProvider{
  GeneralTreeModuleConfig cfg;
  public ABPNavigationProvider(GeneralTreeModuleConfig cfg){
  this.cfg = cfg;
  }
  public override void SetNavigation(INavigationProviderContext context){
    //其它菜单配置
    var sjzd = cfg.InitNav(jczl);
    sjzd.Icon = "shuju";
    sjzd.Url = "/baseinfo/generalTree/index.html";

此时你已经可用在项目中使用这个通用的数据字典模块了

 

2.2、扩展通用字典实现“区域”功能

1、定义实体,继承模块提供的抽象类

[Table("ABPAdministratives")]
public class AdministrativeEntity : GeneralTreeEntity<AdministrativeEntity>{
  /// <summary>
  /// 行政区域级别
  /// </summary>
  public XZQ Level { get; set; } 
}

2、配置DbContext

public class ABPDbContext : AbpZeroDbContext<Tenant, Role, User>{
//其它配置
public virtual DbSet<AdministrativeEntity> Administratives { get; set; }

3、定义领域服务类

public class AdministrativeManager : GeneralTreeManager<AdministrativeEntity>{
  public AdministrativeManager(IRepository<AdministrativeEntity, long> repository) : base(repository){
  }
}

4、按abp常规套路实现Application中的接口和dto,偷个懒,截个图

 

[AutoMapFrom(typeof(AdministrativeEntity))]
public class AdministrativeDto : GeneralTreeGetTreeNodeBaseDto<AdministrativeDto> {
  public XZQ Level { get; set; }
  public string LevelText { get; set; }
}
[AutoMapTo(
typeof(AdministrativeEntity))] public class EditAdministrativetDto: GeneralTreeNodeEditBaseDto{   [Range(0, 3)]   public int Level { get; set; } } public interface IAdministrativeAppService : IGeneralTreeAppServiceBase<AdministrativeDto,EditAdministrativetDto> {} public class AdministrativeAppService : GeneralTreeAppServiceBase<AdministrativeEntity, AdministrativeDto, EditAdministrativetDto>, IAdministrativeAppService{   public AdministrativeAppService(     IRepository<AdministrativeEntity, long> repository,     AdministrativeManager organizationUnitManager)     : base(repository,       organizationUnitManager,       PermissionNames.AdministratorBaseInfoAdministrativeAdd,       PermissionNames.AdministratorBaseInfoAdministrativeUpdate,       PermissionNames.AdministratorBaseInfoAdministrativeDelete,       PermissionNames.AdministratorBaseInfoAdministrative,       "Nationwide", "Administrative")     {}   protected override void OnGetAllListItem(AdministrativeEntity entity, AdministrativeDto dto){     dto.LevelText = base.LocalizationSource.GetEnum(entity.Level);   }   protected override void OnGetForSelectItem(AdministrativeEntity entity, GeneralTreeNodeDto node){     node.attributes.Level = entity.Level;     node.attributes.LevelText = base.LocalizationSource.GetEnum(entity.Level);   }

 

三、总结
本篇只讲了使用,下篇会详细分析如何用abp实现模块化

 

Guess you like

Origin www.cnblogs.com/jionsoft/p/12074072.html