zoukankan      html  css  js  c++  java
  • abp学习日志五(领域服务)

    应用 Application

    这一层更多的是逻辑运算,把Dto转化为实体,聚合根等。

    Dto是一个非常不错的分层,关于Dto,Vo,Do,Po的详解在第一篇已经介绍abp学习日记 初记

    ProductService

    using LY.Shop.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Volo.Abp.Application.Services;
    using Volo.Abp.Domain.Repositories;
    
    namespace LY.Shop
    {
        public class ProductService : CrudAppService<Product, ProductDto, Guid, PageProductDto, CreateProductDto, UpdateProductDto>, IProductService
        {
            private readonly IRepository<Product, Guid> _productRepository;
            public ProductService(IRepository<Product, Guid> productRepository) : base(productRepository)
            {
                _productRepository = productRepository;
            }
    
            public Task<ProductDto> AddAsync(ProductDto product)
            {
                var result = _productRepository.InsertAsync(new Product(GuidGenerator.Create()) { ProductPrice = 1, ProductUnit = "个", ProductName = product.Name }).ContinueWith(task =>
                             {
                                 return product;
                             });
                return result;
            }
    
            public Task<ProductDto> GetAsync()
            {
                var result = _productRepository.FirstOrDefault();
                return Task.FromResult(new ProductDto()
                {
                    Name = result.ProductName
                });
            }
    
            public Task<ProductDto> GetAuthorizedAsync()
            {
                return Task.FromResult(
                    new ProductDto
                    {
                        Name = "aaa"
                    }
                );
            }
        }
    }
    
    

    ICrudAppService 接口

    public interface ICrudAppService<
        TEntityDto,
        in TKey,
        in TGetListInput,
        in TCreateInput,
        in TUpdateInput>
        : IApplicationService
        where TEntityDto : IEntityDto<TKey>
    {
        Task<TEntityDto> GetAsync(TKey id);
    
        Task<PagedResultDto<TEntityDto>> GetListAsync(TGetListInput input);
    
        Task<TEntityDto> CreateAsync(TCreateInput input);
    
        Task<TEntityDto> UpdateAsync(TKey id, TUpdateInput input);
    
        Task DeleteAsync(TKey id);
    }
    

    对常用的CURD操作做了基本约束

    为了方便使用,框架还给做了实现 CrudAppService

    遇到了麻烦

    在使用过程中遇到了麻烦,不是技术问题,是工作量的问题,根据接口的泛型和泛型约束,要创建多个Dto,确实麻烦的要死,当然可以只用一个Dto。但是这个工作量也很大,如果网上没有工具,最好自己开发一个自动生成代码的工具。

  • 相关阅读:
    如何Android Apk反编译得到Java源代码
    安卓反编译揭秘!!
    Android Apk反编译得到Java源代码
    玩手游虽易保安全不易,打造手游App定制加密方案
    LR学习笔记2-LoadRunner目录分析
    LR学习笔记1-性能测试常见用语
    [MySql视图的使用]
    SQL实训
    Mysql_删除主键
    [SQL提数]函数的灵活使用
  • 原文地址:https://www.cnblogs.com/xiaoch/p/13417914.html
Copyright © 2011-2022 走看看