美文网首页
创建ABP模块(四)应用层

创建ABP模块(四)应用层

作者: 寻找无名的特质 | 来源:发表于2020-11-19 06:16 被阅读0次

    现在我们创建模块的应用层,首先在项目ZL.MyFirstModule.Application.Contracts中创建Poets目录,在这个目录中创建PoetDto:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Volo.Abp.Application.Dtos;
    
    namespace ZL.MyFirstModule.Poets
    {
        public class PoetDto : AuditedEntityDto<Guid>
        {
            public string Name { get; set; }
            public string Description { get; set; }
        }
    }
    

    还有创建对象的Dto:

    using System.ComponentModel.DataAnnotations;
    
    namespace ZL.MyFirstModule.Poets
    {
        public class CreateUpdatePoetDto 
        {
            [Required]
            [StringLength(128)]
            public string Name { get; set; }
    
            public string Description { get; set; }
        }
    }
    
    

    以及服务接口:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Volo.Abp.Application.Dtos;
    using Volo.Abp.Application.Services;
    
    namespace ZL.MyFirstModule.Poets
    {
        public interface IPoetAppService : ICrudAppService< //Defines CRUD methods
                PoetDto, //Used to show poets
                Guid, //Primary key of the poet entity
                PagedAndSortedResultRequestDto, //Used for paging/sorting
                CreateUpdatePoetDto> //Used to create/update a poet
        {
        }
    }
    
    

    在ZL.MyFirstModule.Application中创建子目录Poets,在这个目录中创建服务的实现:

    namespace ZL.MyFirstModule.Poets
    {
        public class PoetAppService :
            CrudAppService<
                Poet, //The Poet entity
                PoetDto, //Used to show poets
                Guid, //Primary key of the book entity
                PagedAndSortedResultRequestDto, //Used for paging/sorting
                CreateUpdatePoetDto>, //Used to create/update a poet
            IPoetAppService
        {
            public PoetAppService(IRepository<Poet, Guid> repository) : base(repository)
            {
            }
        }
    }
    

    还需要在MyFirstModuleApplicationAutoMapperProfile创建Dto的映射:

                CreateMap<Poet, PoetDto>();
                CreateMap<CreateUpdatePoetDto, Poet>();
    

    我们还需要修改MyFirstModuleApplicationModule中的映射代码:

    using Volo.Abp.Modularity;
    using Volo.Abp.Application;
    
    namespace ZL.MyFirstModule
    {
        [DependsOn(
            typeof(MyFirstModuleDomainModule),
            typeof(MyFirstModuleApplicationContractsModule),
            typeof(AbpDddApplicationModule),
            typeof(AbpAutoMapperModule)
            )]
        public class MyFirstModuleApplicationModule : AbpModule
        {
            public override void ConfigureServices(ServiceConfigurationContext context)
            {
               // context.Services.AddAutoMapperObjectMapper<MyFirstModuleApplicationModule>();
                Configure<AbpAutoMapperOptions>(options =>
                {
                    options.AddMaps<MyFirstModuleApplicationModule>();
                   // options.AddMaps<MyFirstModuleApplicationModule>(validate: true);
                });
            }
        }
    }
    
    

    这些工作完成后,就可以运行应用,并使用swagger测试应用层了:


    图片.png

    相关文章

      网友评论

          本文标题:创建ABP模块(四)应用层

          本文链接:https://www.haomeiwen.com/subject/ipixmktx.html