从零开始学习ABPvNext开发(六)创建应用层

从零开始学习ABPvNext开发(六)创建应用层

2023年7月18日发(作者:)

从零开始学习ABPvNext开发(六)创建应⽤层现在我们来创建应⽤层,这样客户端只与应⽤层打交道就可以了。与前⾯创建领域层模块和数据访问EF模块⼀样,我们在解决⽅案中增加.Net Core类库项⽬,作为服务层模块,将项⽬命名为ation,我们需要使⽤Nuget管理器,为项⽬增加必要的依赖项,如下:图⽚.png然后,增加⼀个Abp模块,名称为PoemApplicationModule,这个模块依赖于PoemCoreModule。接下来,创建⼀个⽬录Poems,在这个⽬录中增加⼀个Dto类PoetDto:namespace { public class PoetDto:EntityDto { public string Name { get; set; } public string Description { get; set; } }}DTO的⽬的是隔离客户端与领域模型,但很多情况下,DTO与领域模型基本上是相同的,ABP使⽤AutoMapper实现DTO到领域实体的映射。这需要创建⼀个映射Profile:using ;namespace { public class PoemAppAutoMapperProfile : Profile { public PoemAppAutoMapperProfile() { CreateMap(); } }}还需要在模块中进⾏声明:using System;using pper;using rity;using ;using ;namespace ation{ [DependsOn( typeof(PoemCoreModule),

typeof(AbpAutoMapperModule))] public class PoemApplicationModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => { file(validate: true); }); } }}现在创建IPoemAppService接⼝:using System;using ;using es;namespace { public interface IPoemAppService:IApplicationService { ///

/// 获取诗⼈分页 /// /// /// PagedResultDto GetPagedPoets(PagedResultRequestDto dto); }}我们先只增加⼀个函数,获取分页的诗⼈。然后我们创建PoemAppService:using c;using ;using ;using es;using tories;using ;using ;namespace { public class PoemAppService : ApplicationService, IPoemAppService { private readonly IRepository _poetRepository; public PoemAppService(IRepository poetRepository) { _poetRepository = poetRepository; } public PagedResultDto GetPagedPoets(PagedResultRequestDto dto) { using (var uow = (new AbpUnitOfWorkOptions())) { var count = _(); var lst = _y(o => ).PageBy(dto).ToList(); var items = new List();

return new PagedResultDto { TotalCount = count, Items = , List>(lst) }; }

} }}到这⾥,应⽤层编写完成,下⾯使⽤Client调⽤应⽤层。⾸先,在PoemConsoleClientModule中增加PoemApplicationModule依赖:using c;using rity;using ation;using ;using ;namespace eClient{ [DependsOn( typeof(AbpAutofacModule), typeof(PoemCoreModule), typeof(PoemApplicationModule), typeof(PoemDataModule))] public class PoemConsoleClientModule:AbpModule { }}然后,改造Service,使⽤服务层访问数据:using FrameworkCore;using System;using ;using encyInjection;using tories;using ;using ;using ;namespace eClient{ public class Service : ITransientDependency { //IRepository repository; //IUnitOfWorkManager uowManager; IPoemAppService appService; //public Service(IRepository repository, IUnitOfWorkManager uowManager) //{ // tory = repository; // ager = uowManager; //} public Service(IPoemAppService appService) { vice = appService; } public void Run() { //ine("你好"); //using (var uow = (new AbpUnitOfWorkOptions())) //{ // //获取第⼀个诗⼈ // //var poet = rDefault(); // var poet = yable().Include(p => ).FirstOrDefault(); // ine(); // ine(()); // ine(()[0].); //} var res=edPoets(new esultRequestDto { MaxResultCount = 10, SkipCount = 0 }); ine(ount); foreach(var dto in ) { ine(); } } }}运⾏如下:图⽚.png

发布者:admin,转转请注明出处:http://www.yc00.com/web/1689643729a273281.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信