41 lines
980 B
C#
41 lines
980 B
C#
using MassTransit;
|
|
using MediatR;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace IM.DomainCommons
|
|
{
|
|
public class BaseEntity : IEntity, IDomainEvents
|
|
{
|
|
/// <summary>
|
|
/// 这里使用连续guid,防止数据库性能问题
|
|
/// </summary>
|
|
public Guid Id { get; private set; } = NewId.NextGuid();
|
|
|
|
[NotMapped]
|
|
public List<INotification> 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<INotification> GetDomainEvents()
|
|
{
|
|
return domainEvents;
|
|
}
|
|
}
|
|
}
|