AkbarAmd.SharedKernel.Application 1.0.19

dotnet add package AkbarAmd.SharedKernel.Application --version 1.0.19
                    
NuGet\Install-Package AkbarAmd.SharedKernel.Application -Version 1.0.19
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AkbarAmd.SharedKernel.Application" Version="1.0.19" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AkbarAmd.SharedKernel.Application" Version="1.0.19" />
                    
Directory.Packages.props
<PackageReference Include="AkbarAmd.SharedKernel.Application" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AkbarAmd.SharedKernel.Application --version 1.0.19
                    
#r "nuget: AkbarAmd.SharedKernel.Application, 1.0.19"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AkbarAmd.SharedKernel.Application@1.0.19
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AkbarAmd.SharedKernel.Application&version=1.0.19
                    
Install as a Cake Addin
#tool nuget:?package=AkbarAmd.SharedKernel.Application&version=1.0.19
                    
Install as a Cake Tool

AkbarAmd.SharedKernel.Application

Clean Architecture Application Layer - CQRS, MediatR, Validation, and Application Services

Overview

The Application layer orchestrates business operations and coordinates between the Domain and Infrastructure layers. This package provides CQRS patterns, command/query handlers, DTOs, and service result models for building maintainable application services.

Purpose

This layer defines:

  • CQRS contracts (Commands, Queries, Events)
  • Handler base classes for MediatR integration
  • DTOs for data transfer between layers
  • Service results for standardized operation outcomes
  • Mapping utilities for object transformation

Key Components

CQRS Contracts

  • ICommand: Base interface for commands (state-changing operations)
  • ICommand<TResult>: Command that returns a result
  • IQuery<TResult>: Base interface for queries (read operations)
  • IEvent: Integration event interface for cross-bounded context communication

Handler Base Classes

  • CommandHandler<TCommand>: Base class for command handlers
  • CommandHandler<TCommand, TResult>: Base class for command handlers with return values
  • QueryHandler<TQuery, TResult>: Base class for query handlers
  • EventHandler<TEvent>: Base class for event handlers
  • DomainEventHandler<TEvent>: Base class for domain event handlers

Service Results

  • ServiceResult: Result model for operations without return data
  • ServiceResult<T>: Result model for operations with return data
  • ValidationResult: Validation error result model
  • PaginatedResult<T>: Paginated query result model

DTOs

  • EntityDto<TKey>: Base DTO for entities
  • AggregateDto<TKey>: Base DTO for aggregate roots
  • CreatableAggregateDto<TKey>: DTO with creation tracking
  • ModifiableAggregateDto<TKey>: DTO with modification tracking
  • DeletableAggregateDto<TKey>: DTO with deletion tracking

Mapping

  • IMapper: Mapping interface abstraction
  • ServiceCollectionMapperExtensions: Extension methods for mapper registration

Features

  • CQRS Pattern: Clean separation of commands and queries
  • MediatR Integration: Decoupled communication via mediator pattern
  • Handler Lifecycle: Built-in validation, logging, and error handling hooks
  • Service Results: Standardized operation outcomes with error handling
  • DTO Support: Base DTOs for common aggregate root patterns
  • Mapping Abstraction: Framework-agnostic mapping interface

Installation

dotnet add package AkbarAmd.SharedKernel.Application

Usage Examples

Creating a Command Handler

public class CreateUserCommand : ICommand<Guid>
{
    public string Email { get; set; }
    public string Name { get; set; }
}

public class CreateUserCommandHandler : CommandHandler<CreateUserCommand, Guid>
{
    private readonly IRepository<User, Guid> _userRepository;

    public CreateUserCommandHandler(IRepository<User, Guid> userRepository)
    {
        _userRepository = userRepository;
    }

    protected override async Task<Guid> ProcessAsync(
        CreateUserCommand request, 
        CancellationToken cancellationToken)
    {
        var user = new User(request.Email, request.Name);
        await _userRepository.AddAsync(user, cancellationToken);
        return user.Id;
    }
}

Creating a Query Handler

public class GetUserQuery : IQuery<UserDto>
{
    public Guid UserId { get; set; }
}

public class GetUserQueryHandler : QueryHandler<GetUserQuery, UserDto>
{
    private readonly IReadOnlyRepository<User, Guid> _userRepository;
    private readonly IMapper _mapper;

    protected override async Task<UserDto> ProcessAsync(
        GetUserQuery request, 
        CancellationToken cancellationToken)
    {
        var user = await _userRepository.GetByIdAsync(request.UserId, cancellationToken);
        return _mapper.Map<UserDto>(user);
    }
}

Using Service Results

public async Task<ServiceResult<UserDto>> GetUserAsync(Guid userId)
{
    var user = await _userRepository.GetByIdAsync(userId);
    
    if (user == null)
        return ServiceResult<UserDto>.Failure("User not found", "USER_NOT_FOUND");
    
    var dto = _mapper.Map<UserDto>(user);
    return ServiceResult<UserDto>.Success(dto);
}

Creating Integration Events

public class UserCreatedEvent : IEvent
{
    public Guid Id { get; } = Guid.NewGuid();
    public DateTime OccurredOn { get; } = DateTime.UtcNow;
    public string? CorrelationId { get; set; }
    public string Source { get; } = "UserService";
    
    public Guid UserId { get; }
    public string Email { get; }

    public UserCreatedEvent(Guid userId, string email)
    {
        UserId = userId;
        Email = email;
    }
}

Dependencies

  • MediatR 12.5.0: Mediator pattern implementation
  • FluentValidation 11.5.0: Validation framework
  • AutoMapper 12.0.1: Object mapping
  • Microsoft.Extensions.Logging.Abstractions 8.0.3: Logging abstractions
  • Bonyan 1.5.6: Modularity framework

Architecture Principles

This layer follows Clean Architecture principles:

  • Depends on Domain layer only
  • No infrastructure dependencies (except abstractions)
  • Application logic orchestration
  • Framework integration (MediatR, AutoMapper)

License

MIT License - see LICENSE file for details.

Author

Akbar Ahmadi Saray - GitHub

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.19 0 11/30/2025
1.0.18 32 11/29/2025
1.0.17 266 11/11/2025
1.0.16 264 11/11/2025
1.0.15 180 10/20/2025
1.0.14 162 10/20/2025
1.0.13 326 9/16/2025
1.0.11 191 8/18/2025
1.0.10 113 8/3/2025
1.0.9 117 8/3/2025
1.0.8 113 8/3/2025

Version 1.0.19:
- Updated to support nested includes from Domain layer
- Enhanced application layer compatibility with new IncludeChain functionality

Version 1.0.18:
- Updated ModifiableAggregateDto to use ModifiedAt/ModifiedBy instead of LastModifiedAt/LastModifiedBy
- Breaking change: ModifiableAggregateDto properties renamed from LastModifiedAt/LastModifiedBy to ModifiedAt/ModifiedBy