AkbarAmd.SharedKernel.Domain
1.0.23
See the version list below for details.
dotnet add package AkbarAmd.SharedKernel.Domain --version 1.0.23
NuGet\Install-Package AkbarAmd.SharedKernel.Domain -Version 1.0.23
<PackageReference Include="AkbarAmd.SharedKernel.Domain" Version="1.0.23" />
<PackageVersion Include="AkbarAmd.SharedKernel.Domain" Version="1.0.23" />
<PackageReference Include="AkbarAmd.SharedKernel.Domain" />
paket add AkbarAmd.SharedKernel.Domain --version 1.0.23
#r "nuget: AkbarAmd.SharedKernel.Domain, 1.0.23"
#:package AkbarAmd.SharedKernel.Domain@1.0.23
#addin nuget:?package=AkbarAmd.SharedKernel.Domain&version=1.0.23
#tool nuget:?package=AkbarAmd.SharedKernel.Domain&version=1.0.23
AkbarAmd.SharedKernel.Domain
Clean Architecture Domain Layer - Core Domain Models, Entities, Value Objects, and Domain Events
Overview
The Domain layer is the core of Clean Architecture, containing business logic, domain models, and domain rules. This package provides foundational building blocks for implementing Domain-Driven Design (DDD) patterns in .NET applications.
Purpose
This layer defines:
- Business entities and their relationships
- Business rules for domain invariants and validation
- Domain rules and business invariants
- Value objects for domain concepts
- Domain events for domain state changes
- Specifications for complex business queries
- Aggregate roots that enforce consistency boundaries
Key Components
Entities & Aggregate Roots
Entity<TKey>: Base entity class with identity managementAggregateRoot<TKey>: Aggregate root with domain events and concurrency controlCreatableAggregateRoot<TKey>: Aggregate root with creation trackingModifiableAggregateRoot<TKey>: Aggregate root with modification trackingSoftDeletableAggregateRoot<TKey>: Aggregate root with soft delete supportFullAggregateRoot<TKey>: Complete aggregate root with all tracking features
Value Objects
ValueObject: Immutable value object base classEnumeration: Smart enumeration pattern for domain constants
Domain Events
IDomainEvent: Interface for domain events- Built-in domain event management within aggregate roots
- Thread-safe domain event collection
Business Rules
IBusinessRule: Interface for domain business rules and invariantsBaseBusinessRule: Base class for implementing business rulesDomainBusinessRuleValidationException: Exception thrown when business rules are violated
Specifications
ISpecification<T>: Specification pattern interfaceBaseSpecification<T>: Base class for building specificationsFluentSpecificationBuilder<T>: Fluent API for building query criteriaCriteriaChain<T>: Chain multiple criteria together
Outbox Pattern
OutboxMessage: Aggregate root for reliable message processing- Status tracking and retry mechanism
- Domain events for state changes
Repositories
IRepository<T, TKey>: Generic repository interfaceIReadOnlyRepository<T, TKey>: Read-only repository interface
Features
- Domain-Driven Design: Full DDD support with aggregate roots and entities
- Event Sourcing Ready: Built-in domain event management
- Audit Trail: Comprehensive audit capabilities (creation, modification, deletion)
- Concurrency Control: Optimistic concurrency with version tracking
- Thread Safety: Thread-safe domain event operations
- Specification Pattern: Complex query building with business rules
- Outbox Pattern: Reliable message processing for distributed systems
Installation
dotnet add package AkbarAmd.SharedKernel.Domain
Usage Examples
Creating an Aggregate Root with Business Rules
using AkbarAmd.SharedKernel.Domain.AggregateRoots;
using AkbarAmd.SharedKernel.Domain.BusinessRules;
public class User : AggregateRoot<Guid>
{
public string Email { get; private set; }
public string Name { get; private set; }
private User() { } // For EF Core
public User(string email, string name)
{
Id = Guid.NewGuid();
// Business rule validation - CheckRule is inherited from Entity base class
CheckRule(new EmailCannotBeEmptyRule(email));
CheckRule(new NameCannotBeEmptyRule(name));
Email = email;
Name = name;
// Raise domain event
AddDomainEvent(new UserCreatedEvent(Id, Email));
}
public void UpdateName(string newName)
{
// Business rule validation
CheckRule(new NameCannotBeEmptyRule(newName));
Name = newName;
AddDomainEvent(new UserNameChangedEvent(Id, newName));
}
public void Deactivate()
{
CheckRule(new UserCanBeDeactivatedRule(IsActive));
IsActive = false;
AddDomainEvent(new UserDeactivatedEvent(Id));
}
}
// Business Rule Implementation
using AkbarAmd.SharedKernel.Domain.BusinessRules;
public class NameCannotBeEmptyRule : BaseBusinessRule
{
private readonly string _name;
public NameCannotBeEmptyRule(string name)
{
_name = name;
}
public override bool IsSatisfied() => !string.IsNullOrWhiteSpace(_name);
public override string Message => "Name cannot be empty";
}
Using Value Objects
public class Email : ValueObject
{
public string Value { get; }
public Email(string value)
{
if (string.IsNullOrWhiteSpace(value) || !value.Contains("@"))
throw new ArgumentException("Invalid email");
Value = value;
}
protected override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
Using Specifications
var activeUsersSpec = new CriteriaBuilder<User>()
.Where(u => u.IsActive)
.OrderBy(u => u.CreatedAt)
.Take(10)
.Build();
var users = await repository.GetAsync(activeUsersSpec);
Dependencies
- .NET 8.0 or later
- No external dependencies (pure domain layer)
Architecture Principles
This layer follows Clean Architecture principles:
- No dependencies on other layers
- Pure business logic without infrastructure concerns
- Framework-agnostic domain models
- Testable in isolation
License
MIT License - see LICENSE file for details.
Author
Akbar Ahmadi Saray - GitHub
| Product | Versions 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. |
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AkbarAmd.SharedKernel.Domain:
| Package | Downloads |
|---|---|
|
AkbarAmd.SharedKernel.Application
Clean Architecture Application Layer - CQRS, MediatR, Validation, and Application Services |
|
|
AkbarAmd.SharedKernel.Infrastructure.EntityFrameworkCore
Clean Architecture Infrastructure Layer - EF Core Integration, Repository Implementations, and Data Access |
|
|
AkbarAmd.SharedKernel.Infrastructure
Clean Architecture Infrastructure Layer - EF Core Integration, Repository Implementations, and Data Access |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.27 | 109 | 2/1/2026 |
| 1.0.26 | 727 | 12/3/2025 |
| 1.0.25 | 716 | 12/2/2025 |
| 1.0.24 | 720 | 12/2/2025 |
| 1.0.23 | 722 | 12/2/2025 |
| 1.0.21 | 685 | 12/2/2025 |
| 1.0.20 | 616 | 12/1/2025 |
| 1.0.19 | 300 | 11/30/2025 |
| 1.0.18 | 167 | 11/29/2025 |
| 1.0.17 | 336 | 11/11/2025 |
| 1.0.16 | 330 | 11/11/2025 |
| 1.0.15 | 215 | 10/20/2025 |
| 1.0.14 | 209 | 10/20/2025 |
| 1.0.13 | 369 | 9/16/2025 |
| 1.0.11 | 232 | 8/18/2025 |
| 1.0.10 | 158 | 8/3/2025 |
| 1.0.9 | 175 | 8/3/2025 |
| 1.0.8 | 157 | 8/3/2025 |
Version 1.0.23:
- Synchronized version with Application and Infrastructure layers
Version 1.0.21:
- Reorganized Business Rules structure to align with DDD principles
- Moved IBusinessRule to Contracts/BusinessRules namespace
- Added BaseBusinessRule abstract class for consistent rule implementation
- Updated Entity and ValueObject to use new BusinessRules namespace
- Enhanced documentation with Business Rules vs Specifications guide
- Improved namespace organization matching Specifications pattern structure
Version 1.0.20:
- Minor updates and bug fixes
Version 1.0.19:
- Added comprehensive nested includes support with IncludeChain and ThenInclude functionality
- Enhanced FluentSpecificationBuilder with IncludeChain method for nested include chains
- Added IncludeChainBuilder for fluent API support of nested includes
- Full support for nullable navigation properties at any level in include chains
- Added comprehensive unit tests for nested includes functionality
- Improved specification pattern with better include chain support
Version 1.0.18:
- Removed Version property and IncrementVersion() method from IAggregateRoot<TId> interface and AggregateRoot<TKey> class
- Renamed LastModifiedAt to ModifiedAt and LastModifiedBy to ModifiedBy in IModifiableAudit interface
- Updated all aggregate root implementations and DTOs to use ModifiedAt/ModifiedBy naming
- Updated Entity Framework Core configurations to reflect property name changes
- Breaking change: Aggregate roots no longer support version-based optimistic concurrency control (RowVersion still available via IConcurrentAudit)
- Breaking change: IModifiableAudit properties renamed from LastModifiedAt/LastModifiedBy to ModifiedAt/ModifiedBy