ABP入门教程(三)添加一个领域层和一个应用层

1 添加一个领域层

前言: ABP自带的Core层我们一般不会修改, 为了项目结构更加清晰建议添加一个Core层, 存放与业务有关的实体

1,在src目录下新建一个项目,类库,例如叫AbpDemo.CoreXxx,
然后添加依赖,照着现有的领域层AbpDemo.Core添加:abp.automapper 和 abp.ZeroCore.EntityFrameworkCore ,添加一样的版本

2,在项目中添加一个实体,一般的首先会添加一个文件夹,实体如下

//系统枚举表,所有表用到的枚举字段都事先插入到此表
    [Table("SysEnum")]
    public class SysEnum : Entity<string>
    {
        /// <summary>
        /// 无效Id,实际Id为Type和Value
        /// </summary>
        [NotMapped]
        public override string Id => $"{Type}-{Value}";

        //类型,与使用此类型的表字段名一致,同时是多语言的Key
        public string Type { get; set; }

        //值,[Type,Value]组成复合主键
        public int Value { get; set; }

        //值标题,必填,用于前端默认显示(不启用多语言的时候)
        public string Name { get; set; }

        /*
        * 预留
         * 多语言的键,必填,
         * 类似英文标题
        */
        public string KeyStr { get; set; }

        //是否启用
        public bool IsEnabled { get; set; }

        //备注
        public string Remark { get; set; }
    }

3,在应用层Application和基础层EntityFrameworkCore添加新项目的依赖

4,按正常流程添加DbSet和服务就可以了

5, 添加一个Module类, 给Application使用

    [DependsOn(typeof(AbpZeroCoreModule))]
    public class CoreXxxModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(CorePcpModule).GetAssembly());
        }
    }

2 添加一个应用层

1, 添加一个类库项目, 例如ProjectName.ApplicationXxx, 要依赖领域层和基础设施层
2, 添加一个Module类, 例如:XxxApplicationModule

    [DependsOn(
        typeof(PlasmaCloudPlatformCoreModule), 
        typeof(CorePcpModule), 
        typeof(AbpAutoMapperModule))]
    public class XxxApplicationModule : AbpModule
    {
        public override void Initialize()
        {
            var thisAssembly = typeof(XxxApplicationModule).GetAssembly();

            IocManager.RegisterAssemblyByConvention(thisAssembly);

            Configuration.Modules.AbpAutoMapper().Configurators.Add(
                // Scan the assembly for classes which inherit from AutoMapper.Profile
                cfg => cfg.AddMaps(thisAssembly)
            );
        }
    }

3, .Web.Core项目要依赖新的应用类, 并在WebCoreModule类中添加如下代码,注册服务

 Configuration.Modules.AbpAspNetCore()
                 .CreateControllersForAppServices(typeof(XxxApplicationModule).GetAssembly());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值