HasDomainEventEntity.cs 664 B

12345678910111213141516171819202122
  1. using AipGateway.API.Domain.IServices.IUtilities;
  2. using System.Collections.Concurrent;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace AipGateway.API.Domain.Common.DomainEvent
  5. {
  6. internal class HasDomainEventEntity : IHasDomainEventEntity
  7. {
  8. [NotMapped]
  9. private readonly ConcurrentQueue<IDomainEvent> _domainEvents = new();
  10. [NotMapped]
  11. public IProducerConsumerCollection<IDomainEvent> DomainEvents => _domainEvents;
  12. protected void PublishEvent(IDomainEvent @event)
  13. {
  14. _domainEvents.Enqueue(@event);
  15. }
  16. protected static Guid NewIdGuid() => Guid.NewGuid();
  17. }
  18. }