NKF.Domain 1.0.1

Requires NuGet 5.0.0 or higher.

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

NKF.Domain

Core domain primitives for Domain-Driven Design in .NET.

Features

  • AggregateRoot<T> — Event-sourced aggregate base with ApplyEventAsync
  • TypedAggregateRoot<T,TId> — Strongly-typed aggregate base with EntityId and event sourcing
  • Entity<T> — Base entity with auditing (CreatedBy, UpdatedBy, Soft Delete) and ITenantAware (TenantId [NotMapped] + AssignTenantId)
  • TypedEntity<T,TId> — Strongly-typed entity base with TId : EntityId, same auditing + ITenantAware
  • EntityId — Strongly-typed ID ValueObject wrapping Guid (IsEmpty(), ==/!=, ToString()) with EntityIdJsonConverter<TId> for JSON
  • IEntity / IEntity<TId> — Non-typed and typed entity markers
  • ITenantAware — TenantId + AssignTenantId(Guid) for persistence-layer assignment
  • ValueObject — Immutable value equality semantics
  • Enumeration — Type-safe enum pattern
  • Domain Events — IDomainEvent, RaiseDomainEvent, DomainEvents collection
  • Shared Kernels — Cross-domain value objects (CreateDate, UpdateDate, DuplicateContext with typed MapId/GetMappedId<TId>) and DomainErrors.Duplicate

Install

dotnet add package NKF.Domain

Usage

// Non-typed (Guid) aggregate
public class Brand : AggregateRoot<Brand>
{
    public BrandName DefaultName { get; private set; }
    
    public static async Task<Result<Brand>> CreateAsync(string name)
    {
        var nameResult = BrandName.Create(name);
        var brand = new Brand(nameResult.Value);
        
        var evt = new BrandCreatedEvent(brand.Id, name);
        return await brand.ApplyEventAsync<Brand>(evt);
    }
    
    public Result<Brand> Apply(BrandCreatedEvent @event) => Result.Ok(this);
}

// Strongly-typed ID + aggregate (1.0.1)
public sealed class BrandId : EntityId
{
    private BrandId(Guid value) : base(value) { }
    public static Result<BrandId> Create(Guid? value) => !value.HasValue || value.Value == Guid.Empty ? Result.Fail("Id required") : Result.Ok(new BrandId(value.Value));
    public static Result<BrandId> Create(Guid value) => Create((Guid?)value);
    public static BrandId New() => new(Guid.NewGuid());
}
public class TypedBrand : TypedAggregateRoot<TypedBrand, BrandId>
{
    public BrandName DefaultName { get; private set; } = default!;
    private TypedBrand() { }
    private TypedBrand(BrandId id, BrandName name, Guid userId) : base(id, userId) => DefaultName = name;
    public static async Task<Result<TypedBrand>> CreateAsync(string name, Guid userId)
    {
        var n = BrandName.Create(name);
        if (n.IsFailed) return Result.Fail(n.Errors);
        var b = new TypedBrand(BrandId.New(), n.Value, userId);
        return await b.ApplyEventAsync<TypedBrand>(new BrandCreatedEvent(b.Id.Value, name));
    }
    public Result<TypedBrand> Apply(BrandCreatedEvent @event) => Result.Ok(this);
    protected override TypedBrand CreateDuplicateInstance() => new TypedBrand();
}
// JSON: services.AddControllers().AddJsonOptions(o => o.JsonSerializerOptions.Converters.Add(new EntityIdJsonConverter<BrandId>()));
// Duplicate with typed ID remapping:
var ctx = new DuplicateContext();
var clone = brand.Duplicate(ctx); // auto-remaps BrandId via MapId/GetMappedId<TId>

Repository

github.com/rasoolnikravesh/NKF

License

Apache-2.0

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

Showing the top 3 NuGet packages that depend on NKF.Domain:

Package Downloads
NKF.Persistence.Base

NKF Persistence Base Framework - Repository pattern, Unit of Work, RepositoryCollection auto-discovery, Multi-tenancy

NKF.Persistence.Postgres.Base

NKF Persistence PostgreSQL Base Framework - EF Core PostgreSQL implementation with Command/Query repositories, Unit of Work, Tenant services

NKF.Application.Base

NKF Application Base Framework - CQRS handlers and MediatR pipeline behaviors (Logging, Validation, Performance, Exception, Event publishing)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 124 8/29/2026
1.0.1-beta.1.1 91 8/17/2026
1.0.0 139 8/15/2026

See CHANGELOG.md