PANiXiDA.Core.Domain
1.0.3
dotnet add package PANiXiDA.Core.Domain --version 1.0.3
NuGet\Install-Package PANiXiDA.Core.Domain -Version 1.0.3
<PackageReference Include="PANiXiDA.Core.Domain" Version="1.0.3" />
<PackageVersion Include="PANiXiDA.Core.Domain" Version="1.0.3" />
<PackageReference Include="PANiXiDA.Core.Domain" />
paket add PANiXiDA.Core.Domain --version 1.0.3
#r "nuget: PANiXiDA.Core.Domain, 1.0.3"
#:package PANiXiDA.Core.Domain@1.0.3
#addin nuget:?package=PANiXiDA.Core.Domain&version=1.0.3
#tool nuget:?package=PANiXiDA.Core.Domain&version=1.0.3
PANiXiDA.Core.Domain
PANiXiDA.Core.Domain provides small, reusable domain model building blocks for .NET applications that use Domain-Driven Design patterns.
The package contains base abstractions for entities, aggregate roots, domain events, value objects, and extensible enumerations. It is intentionally lightweight and does not require runtime configuration or infrastructure dependencies.
Installation
Package Manager
dotnet add package PANiXiDA.Core.Domain
PackageReference
<ItemGroup>
<PackageReference Include="PANiXiDA.Core.Domain" Version="1.0.1" />
</ItemGroup>
Requirements
- .NET 10
- Nullable reference types enabled in consuming projects is recommended
Features
- Strongly typed
Entity<TId>base class and non-genericIEntitycontract. AggregateRoot<TId>base class and non-genericIAggregateRootcontract with domain event collection support.DomainEventbase record with generated version 7Guididentifiers and UTC timestamps.ValueObjectbase class with component-based equality.Enumeration<TEnumeration>base class for smart enum-style domain concepts.- Deterministic lookup behavior for enumeration values by identifier or name.
Namespaces
using PANiXiDA.Core.Domain;
using PANiXiDA.Core.Domain.AggregateRoots;
using PANiXiDA.Core.Domain.DomainEvents;
using PANiXiDA.Core.Domain.Entities;
Entity
Use Entity<TId> for domain objects identified by a stable value. The identifier type must be a value type.
The IEntity contract is intentionally non-generic and does not expose identifiers; Id remains available on Entity<TId> implementations.
using PANiXiDA.Core.Domain.Entities;
public sealed class Customer(Guid id) : Entity<Guid>(id)
{
public string Name { get; private set; } = string.Empty;
public void Rename(string name)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
Name = name;
}
}
Aggregate Root and Domain Events
Use AggregateRoot<TId> when an entity is the consistency boundary for a domain model and needs to collect domain events.
The IAggregateRoot contract is intentionally non-generic and does not expose identifiers; Id remains available on AggregateRoot<TId> implementations.
using PANiXiDA.Core.Domain.AggregateRoots;
using PANiXiDA.Core.Domain.DomainEvents;
public sealed class Order(Guid id) : AggregateRoot<Guid>(id)
{
public bool IsStarted { get; private set; }
public void Start()
{
if (IsStarted)
{
return;
}
IsStarted = true;
AddDomainEvent(new OrderStarted(Id));
}
}
public sealed record OrderStarted(Guid OrderId) : DomainEvent;
Domain events are stored inside the aggregate root until the application layer reads and clears them.
Order order = new(Guid.NewGuid());
order.Start();
IReadOnlyCollection<DomainEvent> domainEvents = order.GetDomainEvents();
order.ClearDomainEvents();
DomainEvent assigns:
IdwithGuid.CreateVersion7();OccurredOnUtcwithDateTimeOffset.UtcNow.
The package only stores domain events. It does not dispatch, publish, persist, or serialize them.
Value Object
Use ValueObject for immutable concepts where equality is based on values instead of identity.
using PANiXiDA.Core.Domain;
public sealed class Money(decimal amount, string currency) : ValueObject
{
public decimal Amount { get; } = amount;
public string Currency { get; } = currency;
protected override IEnumerable<object?> GetEqualityComponents()
{
yield return Amount;
yield return Currency;
}
}
Money first = new(10m, "USD");
Money second = new(10m, "USD");
bool areEqual = first == second;
Value object equality uses:
- the same runtime type;
- the ordered sequence returned by
GetEqualityComponents().
Enumeration
Use Enumeration<TEnumeration> for stable, named domain values that need behavior and lookup methods.
using PANiXiDA.Core.Domain;
public sealed class OrderStatus : Enumeration<OrderStatus>
{
public static readonly OrderStatus Draft = new(1, "Draft");
public static readonly OrderStatus Submitted = new(2, "Submitted");
public static readonly OrderStatus Cancelled = new(3, "Cancelled");
private OrderStatus(int id, string name)
: base(id, name)
{
}
}
OrderStatus submitted = OrderStatus.FromId(2);
OrderStatus cancelled = OrderStatus.FromName("Cancelled");
bool found = OrderStatus.TryFromName(" Submitted ", out OrderStatus? status);
IReadOnlyList<OrderStatus> allStatuses = OrderStatus.GetAll();
Enumeration behavior:
GetAll()returns public static values declared on the concrete type ordered byId.FromId(int)andFromName(string)return a value or throwInvalidOperationException.TryFromId(int, out TEnumeration?)returnsfalsewhen no value exists.TryFromName(string, out TEnumeration?)trims surrounding whitespace and returnsfalsefor empty or whitespace names.- Names are compared with
StringComparer.Ordinal. - Duplicate identifiers or names throw
InvalidOperationExceptionduring cache creation. - Equality and ordering are based on identifiers within the concrete enumeration type.
Configuration
The package does not require runtime configuration, environment variables, external services, or dependency injection registration.
Development
Restore
dotnet restore
Format
dotnet format
Build
dotnet build --configuration Release
Test
dotnet test --configuration Release
Test with Coverage
dotnet test --configuration Release --coverage --coverage-output-format xml --coverage-output coverage.xml --results-directory TestResults
Pack
dotnet pack --configuration Release
Repository Layout
.
|-- src/
| `-- PANiXiDA.Core.Domain/
|-- tests/
| `-- PANiXiDA.Core.Domain.UnitTests/
|-- Directory.Build.props
|-- Directory.Build.targets
|-- Directory.Packages.props
|-- global.json
|-- version.json
|-- LICENSE
`-- README.md
Package Metadata
- Package ID:
PANiXiDA.Core.Domain - Target framework:
net10.0 - Repository:
https://github.com/panixida-dotnet-core/domain - License: Apache-2.0
- Versioning: Nerdbank.GitVersioning
License
This project is licensed under the Apache-2.0 license.
See the LICENSE file for details.
Maintainers
Maintained by PANiXiDA.
| 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
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on PANiXiDA.Core.Domain:
| Package | Downloads |
|---|---|
|
PANiXiDA.Core.Application
Core application-layer abstractions and building blocks for .NET applications, including contracts, messaging, validation, and use case orchestration. |
GitHub repositories
This package is not used by any popular GitHub repositories.