zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.Domain/Entities/BaseAggregateRoot.cs

31 lines
1.1 KiB
C#
Raw Permalink Normal View History

2023-12-05 09:22:48 +00:00
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();
}
}