Moves domain events queue implementation to infrastructure

This commit is contained in:
BinaryAlley committed 2025-02-23 09:47:54 +02:00
1 parent 55c9a4ca1b
commit 98f71b3715
3 files changed
+6 -4

No files matched your search

@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Application.Common.Behaviors;
using Lumina.Application.Common.DomainEvents;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
@@ -34,8 +33,6 @@ public static class ApplicationLayerServices
// register fluent validators
services.AddValidatorsFromAssembly(typeof(ApplicationLayerServices).Assembly);
services.AddScoped<IDomainEventsQueue, DomainEventsQueue>();
return services;
}
}
@@ -1,34 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Events;
using System.Collections.Concurrent;
#endregion
namespace Lumina.Application.Common.DomainEvents;
/// <summary>
/// Represents a thread-safe queue for managing domain events.
/// </summary>
public class DomainEventsQueue : IDomainEventsQueue
{
private readonly ConcurrentQueue<IDomainEvent> _queue = new();
/// <summary>
/// Adds a domain event to the queue.
/// </summary>
/// <param name="domainEvent">The domain event to enqueue.</param>
public void Enqueue(IDomainEvent domainEvent)
{
_queue.Enqueue(domainEvent);
}
/// <summary>
/// Attempts to remove and return the domain event at the beginning of the queue.
/// </summary>
/// <param name="domainEvent">When this method returns, contains the domain event removed from the queue, or the default value of <see cref="IDomainEvent"/> if the queue is empty.
/// </param>
/// <returns><see langword="true"/> if a domain event was successfuly dequeued, <see langword="false"/> otherwise.</returns>
public bool TryDequeue(out IDomainEvent domainEvent)
{
return _queue.TryDequeue(out domainEvent!);
}
}