Generate DDD Aggregate Root structure with Repository Interface, ValueObject, and Domain Event following DDD principles. Use when: - Creating new domain aggregates in DDD projects - Generating aggregate root with repository interface - Scaffolding value objects and domain events - Building domain entities with business invariants - Implementing aggregates with identity and business rules Triggers: "create aggregate", "generate aggregate", "domain aggregate", "aggregate root", "DDD aggregate"
Create a complete DDD Aggregate Root structure following DDD principles.
Applies to:
Aggregate Root:
public class {Entity} : AggregateRoot
{
public Guid Id { get; private set; }
// Properties and business methods
}
Repository Interface:
public interface I{Entity}Repository
{
Task<{Entity}?> GetByIdAsync(Guid id, CancellationToken ct = default);
Task AddAsync({Entity} entity, CancellationToken ct = default);
Task UpdateAsync({Entity} entity, CancellationToken ct = default);
Task DeleteAsync(Guid id, CancellationToken ct = default);
}
ValueObject (optional):
public class {ValueObject} : ValueObject
{
// Immutable value object
protected override IEnumerable<object> GetEqualityComponents()
{
yield return Property1;
yield return Property2;
}
}
Domain Event (optional):
public class {Entity}CreatedEvent : IDomainEvent
{
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
public Guid {Entity}Id { get; init; }
}