Files
f9-web-ai-test/backend/F9WebAiTest.Domain/Entities/AggregateRoot.cs
T
2026-10-08 10:43:59 +08:00

22 lines
771 B
C#

namespace F9WebAiTest.Domain.Entities;
/// <summary>
/// DDD 聚合根基类:BusinessEntity + 领域事件。
/// 聚合根是聚合的入口与唯一代表,外部只能通过聚合根访问聚合内部对象,通过仓储持久化。
/// 参考 BBIT.F9.Domain.Entities.AggregateRoot
/// </summary>
public abstract class AggregateRoot : BusinessEntity, IAggregateRoot
{
private readonly List<IDomainEvent> _domainEvents = new();
public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();
protected void AddDomainEvent(IDomainEvent domainEvent) => _domainEvents.Add(domainEvent);
public void ClearDomainEvents() => _domainEvents.Clear();
}
/// <summary>聚合根标记接口</summary>
public interface IAggregateRoot
{
}