美文网首页
创建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模块(四)应用层

    现在我们创建模块的应用层,首先在项目ZL.MyFirstModule.Application.Contracts中...

  • ABP 模块中AppService自动映射Web Api

    开发ABP应用时,如果创建了应用层的服务AppService,ABP框架在运行时可以将这些服务自动转换为Web A...

  • 创建ABP模块(三)领域层

    前面两节使用ABP CLI创建了模块开发的基础框架,现在开始创建一个简单的应用,完成一个单个实体的CRUD。首先在...

  • 15. WebAPI

    一、概述 Abp框架可以自动、动态的为应用层建立一个web api : 二、使用 2.1 应用层代码: 2.2 查...

  • 创建ABP模块(一)从模板开始

    ABP支持模块化的开发,可以将功能开发成为独立的模块,然后集成到应用中,这样各个模块之间天然没有耦合,便于独立演化...

  • 创建ABP模块(二)模板的发布和使用

    在上一节中,我们使用ABP CLI创建了第一个模块,这个模块可以独立进行开发和调试,现在我们来看一下如何发布和使用...

  • ABP入门系列(1)——通过模板创建MAP版本项目

    ABP入门系列目录——学习Abp框架之实操演练源码路径:Github-LearningMpaAbp 一、从官网创建...

  • ABP 中的 DTO

    ABP的数据传输对象(DTO)负责表示层和应用层之间的数据传递,在应用层中,领域对象会被映射为DTO,返回表示层,...

  • 内部分享之项目架构

    有点空,根据之前内部分享的wiki 做了脱敏,重新画了下图。 整体大概分为四层:应用层,业务模块层,基础模块层,底...

  • ABP 增加菜单

    ABP支持模块化开发,每个模块都可能有自己的菜单,这些菜单需要在模块内部进行维护,调用模块的项目只需要通过Menu...

网友评论

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

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