惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
爱范儿
爱范儿
月光博客
月光博客
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
T
Tailwind CSS Blog
美团技术团队
D
Docker
V
Visual Studio Blog
Martin Fowler
Martin Fowler
博客园 - 聂微东
The Cloudflare Blog

博客园 - 【唐】三三

《python编程从入门到实践》15 生成数据 《python编程从入门到实践》10-11章 文件和异常、测试代码 《python编程从入门到实践》8-9章 函数、类 fastcode 代码理解 AI 框架 Oh-My-OpenCode 3.5.6 完整使用指南 AI工具免费模型排名对比 (2026-02-12) ABP演示 - 分布式 Event Bus(使用rabbitmq) ABP演示 - 工作单元 (UOW) ABP演示 - 异常处理 ABP演示 - 缓存 APP - 实体变更监视事件 [EntityCreatedEventData、EntityUpdatedEventData、EntityDeletedEventData] ABP演示 - 授权 ABP演示 - 本地Event Bus ABP演示 - 实现选项 OPtion LINQ:SelectMany LINQ - Concat、Union、Intersect、Except IEqualityComparer Nginx - 内置变量 vite - vue 打包 vue - 以deifne开头的 API vue - 进阶
ABP演示 - 简单的实现DDD
【唐】三三 · 2026-01-09 · via 博客园 - 【唐】三三
代码类型 放置模块 说明
常量 Domain.Shared 如 AuthorConsts.MaxNameLength
枚举 Domain.Shared 如 BookType 枚举
错误码 Domain.Shared 如 BookStoreDomainErrorCodes
本地化资源 Domain.Shared 如 en.jsonzh-CN.json
实体/聚合根 Domain 如 AuthorBook
领域服务 Domain 如 AuthorManager
业务异常 Domain 如 AuthorAlreadyExistsException
仓储接口 Domain 如 IAuthorRepository
领域事件 Domain 领域内的事件定义
输出 DTO Application.Contracts 如 AuthorDto
输入 DTO Application.Contracts 如 CreateAuthorDtoUpdateAuthorDto
应用服务接口 Application.Contracts 如 IAuthorAppService
权限定义 Application.Contracts 如 BookStorePermissions
权限提供者 Application.Contracts 如 BookStorePermissionDefinitionProvider
应用服务实现 Application 如 AuthorAppService
分布式事件处理器 Application 如集成事件的处理器
仓储实现 EntityFrameworkCore 如 EfCoreAuthorRepository
数据库迁移 EntityFrameworkCore 如 Migrations 文件夹
DbContext EntityFrameworkCore 如 BookStoreDbContext
EventBus 配置 HttpApi.Host / Web 启动时配置事件总线
RabbitMQ 配置 HttpApi.Host / Web 配置文件 + 模块配置类
Redis 配置 HttpApi.Host / Web 配置文件 + 模块配置类
第三方客户端 HttpApi.Host / Domain 视情况而定
后台作业 Application 或 HttpApi.Host 视作业类型而定

Acme.BookStore.Application

Application\Publishers\PublisherAppService.cs

image

Application\BookStoreApplicationAutoMapperProfile.cs

image

Acme.BookStore.Application.Contracts

Application.Contracts\Publishers\CreateUpdatePublisherDto.cs

image

Application.Contracts\Publishers\IPublisherAppService.cs

image

Application.Contracts\Publishers\PublisherDto.cs

image

Acme.BookStore.Domain

Domain\Publishers\Publisher.cs

image

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Domain.Values;

namespace Acme.BookStore.Publishers
{
    public class Publisher : FullAuditedAggregateRoot<Guid>
    {
        [Required]
        [StringLength(PublisherConsts.MaxNameLength)]
        public string Name { get; private set; }

        [StringLength(PublisherConsts.MaxDescriptionLength)]
        public string Description { get; private set; }

        public DateTime EstablishmentTime { get; private set; }
        public Address Address { get; private set; } // 改为只读

        [Url]
        [StringLength(PublisherConsts.MaxUrlLength)]
        public string Url { get; private set; }
        //public string FormattedAddress => Address != null
        //? $"{Address.Street}, {Address.City}, {Address.StateOrProvince}, {Address.PostalCode}, {Address.Country}"
        //: string.Empty;

        private Publisher() { } // 为ORM保留构造

        public Publisher(
            Guid id,
            string name,
            DateTime establishmentTime,
            Address address,
            string description = null,
            string url = null)
        {
            Id = id;
            SetName(name);
            EstablishmentTime = establishmentTime;
            UpdateAddress(address);
            Description = description;
            Url = url;
        }

        public void SetName(string name)
        {
            Name = Check.NotNullOrWhiteSpace(name, nameof(name));
        }

        public void UpdateAddress(Address address)
        {
            Address = Check.NotNull(address, nameof(address));
        }
    }

    public class Address : ValueObject
    {
        /// <summary>
        /// 街道地址,例如:人民路123号。
        /// </summary>
        public string Street { get; set; }

        /// <summary>
        /// 城市名称,例如:北京市。
        /// </summary>
        public string City { get; set; }

        /// <summary>
        /// 州或省份的名称,例如:加利福尼亚州 或 浙江省。
        /// </summary>
        public string StateOrProvince { get; set; }

        /// <summary>
        /// 邮政编码或邮递区号,例如:100000 或 90210。
        /// </summary>
        public string PostalCode { get; set; }

        /// <summary>
        /// 国家名称,例如:中国 或 美国。
        /// </summary>
        public string Country { get; set; }


        private Address() { }

        public Address(string street, string city, string stateOrProvince, string postalCode, string country)
        {
            Street = street;
            City = city;
            StateOrProvince = stateOrProvince;
            PostalCode = postalCode;
            Country = country;
        }

        // 实现ValueObject的抽象方法,以便正确地比较两个Address对象。
        protected override IEnumerable<object> GetAtomicValues()
        {
            yield return Street;
            yield return City;
            yield return StateOrProvince;
            yield return Country;
            yield return PostalCode;
        }

        // 重写ToString方法,以便在调试时更容易地查看Address对象。
        public override string ToString()
        {
            return $"{Street}, {City}, {StateOrProvince}, {PostalCode}, {Country}";
        }
    }
}

Domain\Publishers\IPublisherRepository.cs

image

Acme.BookStore.EntityFrameworkCore

EntityFrameworkCore\EntityFrameworkCore\BookStoreDbContext.cs

image

EntityFrameworkCore\Publishers\EfCorePublisherRepository.cs

image