using MassTransit;
using MediatR;
using System.ComponentModel.DataAnnotations.Schema;
namespace IM.DomainCommons
{
public class BaseEntity : IEntity, IDomainEvents
{
///
/// 这里使用连续guid,防止数据库性能问题
///
public Guid Id { get; private set; } = NewId.NextGuid();
[NotMapped]
public List domainEvents = [];
public void AddDomainEvent(INotification eventItem)
{
domainEvents.Add(eventItem);
}
public void AddDomainEventIfAbsent(INotification eventItem)
{
if (!domainEvents.Contains(eventItem))
{
domainEvents.Add(eventItem);
}
}
public void ClearDomainEvents()
{
domainEvents.Clear();
}
public IEnumerable GetDomainEvents()
{
return domainEvents;
}
}
}