zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.Domain/Entities/BaseAggregateRoot.cs
2023-12-05 17:22:48 +08:00

31 lines
1.1 KiB
C#

using MediatR;
namespace ZeroFramework.DeviceCenter.Domain.Entities
{
public abstract class BaseAggregateRoot : BaseEntity, IAggregateRoot, IDomainEvents
{
private readonly List<INotification> _domainEvents = [];
public IReadOnlyCollection<INotification> DomainEvents => _domainEvents.AsReadOnly();
public void AddDomainEvent(INotification eventItem) => _domainEvents.Add(eventItem);
public void RemoveDomainEvent(INotification eventItem) => _domainEvents?.Remove(eventItem);
public void ClearDomainEvents() => _domainEvents?.Clear();
}
public abstract class BaseAggregateRoot<TKey> : BaseEntity<TKey>, IAggregateRoot, IDomainEvents
{
private readonly List<INotification> _domainEvents = [];
public IReadOnlyCollection<INotification> DomainEvents => _domainEvents.AsReadOnly();
public void AddDomainEvent(INotification eventItem) => _domainEvents.Add(eventItem);
public void RemoveDomainEvent(INotification eventItem) => _domainEvents?.Remove(eventItem);
public void ClearDomainEvents() => _domainEvents?.Clear();
}
}