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
<PackageReference Include="NKF.Domain" Version="1.0.1" />
<PackageVersion Include="NKF.Domain" Version="1.0.1" />
<PackageReference Include="NKF.Domain" />
paket add NKF.Domain --version 1.0.1
#r "nuget: NKF.Domain, 1.0.1"
#:package NKF.Domain@1.0.1
#addin nuget:?package=NKF.Domain&version=1.0.1
#tool nuget:?package=NKF.Domain&version=1.0.1
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
EntityIdand 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()) withEntityIdJsonConverter<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,DomainEventscollection - Shared Kernels — Cross-domain value objects (CreateDate, UpdateDate, DuplicateContext with typed
MapId/GetMappedId<TId>) andDomainErrors.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 | Versions 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. |
-
net10.0
- FluentResults (>= 4.0.0 && < 5.0.0)
- MediatR (>= 14.0.0 && < 15.0.0)
- NKF.Domain.Events (>= 1.0.1)
- NKF.Resources (>= 1.0.1)
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