Kay_Base.SharedKernel.Application 1.0.0

dotnet add package Kay_Base.SharedKernel.Application --version 1.0.0
                    
NuGet\Install-Package Kay_Base.SharedKernel.Application -Version 1.0.0
                    
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="Kay_Base.SharedKernel.Application" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kay_Base.SharedKernel.Application" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Kay_Base.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 Kay_Base.SharedKernel.Application --version 1.0.0
                    
#r "nuget: Kay_Base.SharedKernel.Application, 1.0.0"
                    
#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 Kay_Base.SharedKernel.Application@1.0.0
                    
#: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=Kay_Base.SharedKernel.Application&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Kay_Base.SharedKernel.Application&version=1.0.0
                    
Install as a Cake Tool

Kay Base SharedKernel

A comprehensive .NET 9 SharedKernel package implementing Clean Architecture patterns, providing reusable components for enterprise applications.

Overview

This SharedKernel provides a solid foundation for building scalable, maintainable applications following Clean Architecture principles. It includes domain primitives, CQRS patterns, validation behaviors, caching, notifications, and more.

Architecture

The SharedKernel is organized into four main layers:

  • Domain - Core business logic, entities, value objects, and domain events
  • Application - Use cases, commands, queries, and application behaviors
  • Infrastructure - External concerns like caching, background jobs, and services
  • Persistence - Data access, repositories, specifications, and audit trails
  • Presentation - API controllers and exception handling

Packages

Kay_Base.SharedKernel.Domain

Core domain primitives and business logic components.

Key Components:

  • Entities & Aggregates: Base classes for domain entities with proper equality semantics
  • Value Objects: Strongly-typed value objects (EmailAddress, Money, PhoneNumber, etc.)
  • Domain Events: Event-driven architecture support with IDomainEvent
  • Results Pattern: Robust error handling with Result<T> and IResult
  • Enums: Common enumerations (Gender, SortDirection, NotificationType)

Kay_Base.SharedKernel.Application

CQRS patterns and application layer abstractions.

Key Components:

  • CQRS: Command/Query interfaces with MediatR integration
  • Behaviors: Validation, logging, and unit of work pipeline behaviors
  • Abstractions: Interfaces for caching, messaging, and external services
  • Pagination: Built-in paginated query support

Kay_Base.SharedKernel.Infrastructure

External integrations and cross-cutting concerns.

Key Components:

  • Caching: Distributed and in-memory cache implementations
  • Background Jobs: Hangfire integration with outbox pattern processing
  • Services: AWS S3, email notifications, current user context
  • Resilience: Polly-based retry policies

Kay_Base.SharedKernel.Persistence

Data access patterns and persistence concerns.

Key Components:

  • Unit of Work: Transaction management
  • Repository Pattern: Generic repository with specifications
  • Audit Trails: Automatic audit logging for entity changes
  • Outbox Pattern: Reliable domain event publishing
  • Specifications: Flexible query building with reusable specifications

Kay_Base.SharedKernel.Presentation

API layer components and exception handling.

Key Components:

  • Base Controller: Common API controller functionality
  • Global Exception Handler: Centralized error handling
  • Result Extensions: Automatic HTTP status code mapping

Installation

Install the packages via NuGet Package Manager or .NET CLI:

# Core domain components
dotnet add package Kay_Base.SharedKernel.Domain

# Application layer with CQRS
dotnet add package Kay_Base.SharedKernel.Application

# Infrastructure services
dotnet add package Kay_Base.SharedKernel.Infrastructure

# Data access and persistence
dotnet add package Kay_Base.SharedKernel.Persistence

# API presentation layer
dotnet add package Kay_Base.SharedKernel.Presentation

Quick Start

1. Domain Layer Setup

Create entities inheriting from base classes:

public class User : AggregateRoot
{
    public UserId Id { get; private set; }
    public FirstName FirstName { get; private set; }
    public LastName LastName { get; private set; }
    public EmailAddress Email { get; private set; }
    
    // Domain logic here
}

2. Application Layer Setup

Implement commands and queries:

public record CreateUserCommand(
    string FirstName,
    string LastName, 
    string Email) : ICommand<UserId>;

public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, UserId>
{
    public async Task<IResult<UserId>> Handle(CreateUserCommand request, CancellationToken cancellationToken)
    {
        // Implementation
    }
}

3. Infrastructure Registration

Configure services in your startup:

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplication();
    services.AddInfrastructure(configuration);
    services.AddPersistence(configuration);
    services.AddPresentation();
}

4. API Controllers

Create controllers inheriting from BaseApiController:

[Route("api/[controller]")]
public class UsersController : BaseApiController
{
    [HttpPost]
    public async Task<IActionResult> CreateUser(CreateUserCommand command)
    {
        var result = await Mediator.Send(command);
        return result.Match(
            onSuccess: id => CreatedAtAction(nameof(GetUser), new { id }, id),
            onFailure: HandleFailure);
    }
}

Key Features

Result Pattern

Robust error handling without exceptions:

public static Result<User> Create(string email, string firstName)
{
    var emailResult = EmailAddress.Create(email);
    if (emailResult.IsFailure)
        return Result.Failure<User>(emailResult.Error);
        
    var nameResult = FirstName.Create(firstName);
    if (nameResult.IsFailure)
        return Result.Failure<User>(nameResult.Error);
        
    return Result.Success(new User(emailResult.Value, nameResult.Value));
}

Value Objects

Strongly-typed primitives with validation:

var email = EmailAddress.Create("user@example.com");
var money = Money.Create(100.50m, "USD");
var phone = PhoneNumber.Create("+1234567890");

Domain Events

Event-driven architecture:

public class UserCreatedDomainEvent : DomainEvent
{
    public UserId UserId { get; }
    public EmailAddress Email { get; }
    
    public UserCreatedDomainEvent(UserId userId, EmailAddress email)
    {
        UserId = userId;
        Email = email;
    }
}

Specifications

Flexible, reusable query building:

public class ActiveUsersSpecification : ISpecification<User>
{
    public Expression<Func<User, bool>> Criteria => user => user.IsActive;
    public List<Expression<Func<User, object>>> Includes => new();
}

Pagination Support

Built-in paginated queries:

public record GetUsersQuery(int Page, int PageSize) : IPaginatedQuery<UserResponse>;

public class GetUsersQueryHandler : IPaginatedQueryHandler<GetUsersQuery, UserResponse>
{
    public async Task<IResult<PaginatedResult<UserResponse>>> Handle(
        GetUsersQuery request, 
        CancellationToken cancellationToken)
    {
        // Implementation with automatic pagination
    }
}

Design Patterns

  • Clean Architecture: Clear separation of concerns across layers
  • CQRS: Command Query Responsibility Segregation with MediatR
  • Repository Pattern: Abstracted data access with specifications
  • Unit of Work: Transaction management across repositories
  • Outbox Pattern: Reliable domain event publishing
  • Result Pattern: Functional error handling without exceptions
  • Domain Events: Event-driven architecture support
  • Value Objects: Strongly-typed primitives with built-in validation

Dependencies

  • .NET 9.0
  • MediatR 12.5.0
  • FluentValidation 11.11.0
  • MassTransit 8.4.0
  • Entity Framework Core (for persistence)
  • Hangfire (for background jobs)

Contributing

This SharedKernel is designed to be extended and customized for your specific domain needs. Feel free to inherit from the base classes and implement your own domain-specific logic.

License

[Add your license information here]

Support

[Add support/contact information here]

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Kay_Base.SharedKernel.Application:

Package Downloads
Kay_Base.SharedKernel.Persistence

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 274 7/20/2025