# Abp Domain

> ABP 领域层 — 实体、聚合根、值对象、领域服务。Use when designing domain entities, aggregate roots, value objects in ABP.

- Skill: `liaosw97/abp-domain` (Agent Skill)
- Install (CLI): `npx skillmds@latest add liaosw97/abp-domain`
- Raw SKILL.md: https://api.skillmd.com/api/skills/liaosw97/abp-domain/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: liaosw97 (https://skillmd.com/u/liaosw97)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/liaosw97/abp-domain

---


# ABP 领域层

## 聚合根定义

```csharp
public class User : AggregateRoot<Guid>
{
    public string UserName { get; private set; }
    public string Email { get; private set; }

    private User() { } // ORM 需要

    public User(Guid id, string userName, string email) : base(id)
    {
        UserName = userName;
        Email = email;
    }

    public void UpdateEmail(string email)
    {
        Email = email;
        AddLocalEvent(new UserEmailChangedEvent(Id, email));
    }
}
```

## 值对象

```csharp
public class EmailAddress : ValueObject
{
    public string Address { get; private set; }

    private EmailAddress() { }

    public EmailAddress(string address)
    {
        Address = address;
    }

    protected override IEnumerable<object> GetAtomicValues()
    {
        yield return Address;
    }
}
```

## 仓储接口

```csharp
public interface IUserRepository : IRepository<User, Guid>
{
    Task<User?> FindByUserNameAsync(string userName);
}
```
