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,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Over18;
@@ -10,6 +11,7 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
using Lumina.Infrastructure.Common.DomainEvents;
using Lumina.Infrastructure.Core.Authentication;
using Lumina.Infrastructure.Core.Authorization;
using Lumina.Infrastructure.Core.Authorization.Policies.Common.Factory;
@@ -52,6 +54,8 @@ public static class InfrastructureLayerServices
services.AddSingleton<ITotpTokenGenerator, TotpTokenGenerator>();
services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
services.AddScoped<IDomainEventsQueue, DomainEventsQueue>();
// authorization
services.AddScoped<IOver18Policy, Over18Policy>();
services.AddScoped<IAuthorizationPolicyFactory, AuthorizationPolicyFactory>();
@@ -0,0 +1,35 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DomainEvents;
using Lumina.Domain.Common.Events;
using System.Collections.Concurrent;
#endregion
namespace Lumina.Infrastructure.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!);
}
}