Implements domain events queue processing and eventual consistency

This commit is contained in:
BinaryAlley committed 2025-01-04 17:42:40 +02:00
1 parent f96cfa4a2f
commit 80e2ce0f82
10 files changed
+198 -9

No files matched your search

@@ -1,3 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Events;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Common.Models.Core;
/// <summary>
@@ -6,6 +11,8 @@ namespace Lumina.Domain.Common.Models.Core;
/// <typeparam name="TId">The type representing the unique identifier for the Aggregate Root. It should be a non-nullable type.</typeparam>
public abstract class AggregateRoot<TId> : Entity<TId> where TId : notnull
{
protected readonly List<IDomainEvent> _domainEvents = [];
/// <summary>
/// Initializes a new instance of the <see cref="AggregateRoot{TId}"/> class.
/// </summary>
@@ -22,4 +29,15 @@ public abstract class AggregateRoot<TId> : Entity<TId> where TId : notnull
{
}
/// <summary>
/// Retrieves and clears all domain events associated with this aggregate root.
/// </summary>
/// <returns>A list of all domain events that were raised by this aggregate root.</returns>
public List<IDomainEvent> PopDomainEvents()
{
List<IDomainEvent> domainEventsCopy = [.. _domainEvents];
_domainEvents.Clear();
return domainEventsCopy;
}
}