This layer will name {namespace}.{feature}
.
The project tree will look like this:
|-- Domain
| |-- AggregrateModel
| |-- AbcAggregrate
| | Abc.cs
| | IAbcRepository.cs // suggested
| |-- XyzAggregrate
| |-- Commands
| |-- CreateAbcCommand.cs
| |-- Events
| |-- AbcCreatedDomainEvent.cs
| |-- CommandHandlers // move it into API project if you are not implementing the Repository
| |-- CreateAbcCommandHandler.cs // to handle create Abc command (as same as Manager)
|-- DependencyInjection // optional
| |-- YourServiceCollectionExtensions.cs // to register your services
In the tree above:
using Juice.Domain;
public class Abc: IAggregrateRoot<INotification>{ // INotification is an interface of MediatR
public Abc() { } // parameterless constructor is needed for EF
public Abc(string name, string correlationId)
{
Name = name;
CorrelationId = correlationId;
}
[Key]
public Guid Id { get; init; }
public string Name { get; init; }
public string CorrelationId { get; init; }
public void UpdateName(string newName){
var originName = Name;
// validation for new name then update it into Name
...
// add a domain event to notice that name was changed
this.AddDomainEvent(new AbcNameChangedDomainEvent(originName, newName));
}
}