Shared : Application

The Shared.Application project provides the application layer abstractions and implementations for a CQRS-based architecture. It includes a lightweight in-process mediator with pipeline behaviors, domain event publishing, repository and service contracts, a Unit of Work pattern, and dependency injection helpers for automated registration.

Abstractions : Repositories

The repository abstractions define marker interfaces for separating read and write concerns :
  • ICommandRepository : A marker interface for repositories that handle write operations (create, update, delete).
  • IQueryRepository : A marker interface for repositories that handle read operations (queries).

Abstractions : Services

The service abstractions define marker interfaces for separating command and query services :
  • ICommandService : A marker interface for services that orchestrate command-side business logic.
  • IQueryService : A marker interface for services that orchestrate query-side business logic.

Abstractions : Unit of Work

The IUnitOfWork interface defines a single SaveChangesAsync method that coordinates the persistence of changes across one or more repositories within a transactional boundary.

Data Providers

The DataProvider static class provides centralized access to common data generation utilities :
  • DateTimes.GetUtcNow : Returns the current UTC date and time.
  • Guids.Create : Generates a new version 7 GUID (time-ordered, sortable).

Dependency Injection

The ApplicationDependencyInjection static class provides helper methods to register all application layer services into the DI container :
  • AddMediator : Registers the IMediator implementation and the logging pipeline behavior.
  • AddCommandServices / AddQueryServices : Registers all concrete types implementing ICommandService or IQueryService by scanning a given assembly.
  • AddCommandHandlers / AddQueryHandlers : Registers command and query handlers as IRequestHandler services using generic type registration.
  • AddCommandHandlerProxies / AddQueryHandlerProxies : Registers handler proxies as IRequestHandler services, allowing cross-cutting concerns to be applied via decorators.
  • AddDomainEventHandlers : Registers all IDomainEventHandler<T> implementations found in the assembly.
  • AddDomainEventPublisher : Registers the IDomainEventPublisher implementation as a scoped service.

Domain Events

The domain event infrastructure provides a publisher and handler contract for dispatching domain events raised by entities :
  • IDomainEventPublisher : An interface defining a PublishAsync method that dispatches a domain event to all registered handlers.
  • IDomainEventHandler<TDomainEvent> : An interface for handling a specific domain event type, with a HandleAsync method.
  • DomainEventPublisher : A sealed implementation of IDomainEventPublisher that resolves all handlers for a given event type from the service provider and invokes them sequentially.

Extensions : Problem Details

The ToErrorListExtension class provides an extension method that converts a ProblemDetailsDto into a list of Error objects, mapping each error string to a validation error type.

Mediator

The mediator infrastructure implements a lightweight in-process CQRS mediator with pipeline behaviors, inspired by MediatR :
  • IRequest<TResponse> : A marker interface for all requests that produce a response of type TResponse.
  • IRequestHandler<TRequest, TResponse> : An interface defining a HandleAsync method for processing a specific request type.
  • ICommand<TResponse> : A marker interface for commands, extending IRequest<Result<TResponse>>.
  • IQuery<TResponse> : A marker interface for queries, extending IRequest<Result<TResponse>>.
  • ICommandHandler<TCommand, TResponse> : A handler interface for commands, extending IRequestHandler.
  • IQueryHandler<TQuery, TResponse> : A handler interface for queries, extending IRequestHandler.
  • ICommandHandlerProxy<TCommand, TResponse> : A proxy interface for command handlers, enabling decorator-based cross-cutting concerns.
  • IQueryHandlerProxy<TQuery, TResponse> : A proxy interface for query handlers, enabling decorator-based cross-cutting concerns.
  • IPipelineBehavior<TRequest, TResponse> : An interface for cross-cutting behaviors that wrap request handling, such as logging or validation.
  • RequestHandlerDelegate<TResponse> : A delegate representing the next action in the pipeline chain.
  • IMediator : An interface defining a SendAsync method to dispatch requests through the pipeline.
  • Mediator : A sealed implementation of IMediator that builds and caches pipeline metadata using expression trees, resolves the handler and behaviors from the service provider, and executes them in a nested delegate chain.

Pipeline Behaviors

The LoggingPipelineBehavior<TRequest, TResponse> class is a sealed pipeline behavior that logs the request name and content before handling, measures execution time with a stopwatch, and logs the response with elapsed milliseconds after handling.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.