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。但是这个工作量也很大,如果网上没有工具,最好自己开发一个自动生成代码的工具。

  • 相关阅读:
    本人实操赚钱项目:月入10万的冷门玩法,人人可操作!
    赚钱项目:1万粉丝的公众号,年赚15万!
    AI 时代下的海量业务智能监控实践
    python 转xe7xbdx97xe5x87xbd 为中文
    python xb5xe7xc6xb1xc7xb0xd6xc3xd6xf7xbbxfa
    12.2 新特性:RMAN 自动恢复到 REDO 终点的步骤简化
    深入认识CSS的块级元素
    深入认识CSS的块级元素
    深入认识CSS的块级元素
    SAP WM TO Print Control设置里,Movement Type 的优先级更高
  • 原文地址:https://www.cnblogs.com/xiaoch/p/13417914.html
Copyright © 2011-2022 走看看