PANiXiDA.Core.Domain
5.0.2
See the version list below for details.
dotnet add package PANiXiDA.Core.Domain --version 5.0.2
NuGet\Install-Package PANiXiDA.Core.Domain -Version 5.0.2
<PackageReference Include="PANiXiDA.Core.Domain" Version="5.0.2" />
<PackageVersion Include="PANiXiDA.Core.Domain" Version="5.0.2" />
<PackageReference Include="PANiXiDA.Core.Domain" />
paket add PANiXiDA.Core.Domain --version 5.0.2
#r "nuget: PANiXiDA.Core.Domain, 5.0.2"
#:package PANiXiDA.Core.Domain@5.0.2
#addin nuget:?package=PANiXiDA.Core.Domain&version=5.0.2
#tool nuget:?package=PANiXiDA.Core.Domain&version=5.0.2
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 strongly typed identifiers, entities, aggregate roots, aggregate repositories, 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="5.0.*" />
</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.IStronglyTypedIdcontract for domain identifiers backed byGuidvalues.IRepository<TId, TAggregateRoot>contract for loading and persisting aggregate roots.DomainEventbase record with generated version 7Guididentifiers and UTC timestamps.IMessagemarker inPANiXiDA.Core.Domain.Abstractions, inherited byIDomainEvent.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.
- Source-generated enumeration lookups, value object methods, and identifier string representations.
- Compiler diagnostics and code fixes for domain conventions.
Namespaces
using PANiXiDA.Core.Domain.Abstractions;
using PANiXiDA.Core.Domain.AggregateRoots;
using PANiXiDA.Core.Domain.DomainEvents;
using PANiXiDA.Core.Domain.Entities;
using PANiXiDA.Core.Domain.Enumerations;
using PANiXiDA.Core.Domain.Identifiers;
using PANiXiDA.Core.Domain.ValueObjects;
Source Generation
Source generators are included in the package. Reference it directly in each
project declaring generated types. Declare the type and any containing types as
partial; file-local types are not supported. Constructors, factories, and
validation are written manually.
With project references, reference PANiXiDA.Core.Domain.SourceGenerators and
PANiXiDA.Core.Domain.Shared as analyzers with OutputItemType="Analyzer" and
ReferenceOutputAssembly="false". Add the same reference to
PANiXiDA.Core.Domain.Analyzers for diagnostics.
Domain conventions
Reference the package directly in each project you want to analyze. The domain
analyzers check state and API conventions at compile time. They report
architecture violations as warnings by default. To treat these diagnostics as
errors, add this to .editorconfig.
[*.cs]
dotnet_analyzer_diagnostic.category-pdomain.severity = error
Apply available fixes in the IDE or run dotnet format analyzers from the
solution root. Use dotnet format analyzers --verify-no-changes to verify
formatter changes and dotnet build to enforce diagnostics configured as
errors.
Strongly Typed Identifier
Use IStronglyTypedId to distinguish domain identifiers from raw Guid values while keeping the underlying value type consistent.
using PANiXiDA.Core.Domain.Identifiers;
public readonly partial record struct CustomerId : IStronglyTypedId
{
private CustomerId(Guid value)
{
Value = value;
}
public Guid Value { get; }
public static CustomerId New()
{
return new CustomerId(Guid.CreateVersion7());
}
}
For partial structs and record structs, the generator adds ToString() returning
Value.ToString(). An explicitly written ToString() takes precedence.
Entity
Use Entity<TId> for domain objects identified by a stable value.
The identifier type must be a value type that implements IStronglyTypedId.
The IEntity contract is intentionally non-generic and does not expose identifiers; Id remains available on Entity<TId> implementations.
using PANiXiDA.Core.Domain.Entities;
using PANiXiDA.Core.Domain.ValueObjects;
public sealed partial class CustomerName : ValueObject
{
public CustomerName(string value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(value);
Value = value;
}
public string Value { get; }
}
public sealed class Customer : Entity<CustomerId>
{
public Customer(CustomerId id, CustomerName name)
: base(id)
{
ArgumentNullException.ThrowIfNull(name);
Name = name;
}
public CustomerName Name { get; private set; }
public void Rename(CustomerName name)
{
ArgumentNullException.ThrowIfNull(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.
Its identifier type must be a value type that implements IStronglyTypedId.
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;
using PANiXiDA.Core.Domain.Identifiers;
using PANiXiDA.Core.Domain.ValueObjects;
public readonly partial record struct OrderId : IStronglyTypedId
{
private OrderId(Guid value)
{
Value = value;
}
public Guid Value { get; }
public static OrderId New()
{
return new OrderId(Guid.CreateVersion7());
}
}
public sealed class Order : AggregateRoot<OrderId>
{
private OrderStartState _startState = new(false);
public Order(OrderId id)
: base(id)
{
}
public bool IsStarted => _startState.Value;
public void Start()
{
if (IsStarted)
{
return;
}
_startState = new OrderStartState(true);
AddDomainEvent(new OrderStarted(Id));
}
}
public sealed partial class OrderStartState : ValueObject
{
public OrderStartState(bool value)
{
Value = value;
}
public bool Value { get; }
}
public sealed record OrderStarted(OrderId OrderId) : DomainEvent;
Domain events are stored inside the aggregate root until the application layer reads and clears them.
Order order = new(OrderId.New());
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.
Repository Abstraction Ownership
Use IRepository<TId, TAggregateRoot> as the base contract for a repository that works with an aggregate root.
The identifier type must be a value type that implements IStronglyTypedId.
using PANiXiDA.Core.Domain.Abstractions;
public interface IOrderRepository : IRepository<OrderId, Order>
{
}
Use asynchronous GetByIdAsync to load an aggregate root. Synchronous Add, Update, and Delete register pending changes.
The persistence adapter is responsible for saving registered changes.
Value Object
Use ValueObject for immutable concepts where equality is based on values instead of identity.
using PANiXiDA.Core.Domain.ValueObjects;
public sealed partial class Money(decimal amount, string currency) : ValueObject
{
public decimal Amount { get; } = amount;
public string Currency { get; } = currency;
}
Money first = new(10m, "USD");
Money second = new(10m, "USD");
bool areEqual = first == second;
string text = first.ToString();
Here, text is Money { Amount = 10, Currency = USD }.
Value object equality uses:
- the same runtime type;
- the ordered sequence returned by
GetEqualityComponents().
For partial value objects, the generator supplies GetEqualityComponents() and
ToString(). Components are public instance auto-properties with a public getter
and either no setter or an init accessor, including inherited properties.
Fields, indexers, mutable properties, and computed getters are excluded.
Override either method to customize it independently; manual overrides, including inherited ones, take precedence. For example, generate equality with custom text:
public sealed partial class Email(string value) : ValueObject
{
public string Value { get; } = value;
public override string ToString() => Value;
}
Generated ToString() prints component names and values using invariant formatting.
With manual GetEqualityComponents(), labels are [0], [1], etc.
If there are no eligible auto-properties, implement GetEqualityComponents() explicitly.
Enumeration
Use Enumeration<TEnumeration> for stable, named domain values that need behavior and lookup methods.
using PANiXiDA.Core.Domain.Enumerations;
public sealed partial class OrderStatus : Enumeration<OrderStatus>
{
public static readonly OrderStatus Draft = new(1, "Draft", rank: 10);
public static readonly OrderStatus Submitted = new(2, "Submitted", rank: 20);
public static readonly OrderStatus Cancelled = new(3, "Cancelled");
private OrderStatus(int id, string name, int? rank = null)
: base(id, name, rank)
{
}
}
OrderStatus submitted = OrderStatus.FromId(2);
OrderStatus cancelled = OrderStatus.FromName("Cancelled");
bool found = OrderStatus.TryFromName(" Submitted ", out OrderStatus? status);
IReadOnlyList<OrderStatus> allStatuses = OrderStatus.GetAll();
The generator adds GetAll, FromId, FromName, TryFromId, and TryFromName
directly to the partial class. Declare values as public static readonly fields.
Do not call lookup methods from static field initializers or declare methods with
the same signatures as the generated methods.
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.FromName(string)andTryFromName(string, out TEnumeration?)share the same lookup and trim surrounding whitespace.TryFromNamereturnsfalsefor null, empty, whitespace, or unknown names;FromNamethrowsInvalidOperationExceptionin each of these cases.- Names are compared with
StringComparer.Ordinal. - Duplicate identifiers or names throw
InvalidOperationExceptionon first use. Rankis optional sort metadata for consumers. It defaults tonull, and multiple values can share the same rank.- 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
Build the solution before formatting so generated members are available.
dotnet build --no-restore
dotnet format
Build
dotnet build --configuration Release
Test
dotnet test --configuration Release
The source generator tests share a project with folders for enumerations, strongly typed IDs, and value objects. The analyzer, code fix, and runtime suites have their own projects.
Test with Coverage
To collect coverage for one suite, run its project directly. CI collects and combines reports from all suites.
dotnet test --project tests/Generators/PANiXiDA.Core.Domain.Analyzers.UnitTests --configuration Release --coverage --coverage-output-format xml --coverage-output coverage.xml --results-directory TestResults
Pack
dotnet pack --configuration Release
Continuous integration
Every pull request and push to main runs formatting, tests, and mandatory
SonarQube analysis. Publishing from main starts only after the SonarQube
Quality Gate succeeds.
Repository Layout
PANiXiDA.Core.Domain.Shared provides declaration checks and diagnostic
definitions to Analyzers and SourceGenerators.
.
|-- src/
| |-- Generators/
| | |-- PANiXiDA.Core.Domain.Analyzers/
| | |-- PANiXiDA.Core.Domain.CodeFixes/
| | |-- PANiXiDA.Core.Domain.Shared/
| | `-- PANiXiDA.Core.Domain.SourceGenerators/
| `-- PANiXiDA.Core.Domain/
|-- tests/
| |-- Generators/
| | |-- PANiXiDA.Core.Domain.Analyzers.UnitTests/
| | |-- PANiXiDA.Core.Domain.CodeFixes.UnitTests/
| | `-- PANiXiDA.Core.Domain.SourceGenerators.UnitTests/
| `-- 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 (2)
Showing the top 2 NuGet packages that depend on PANiXiDA.Core.Domain:
| Package | Downloads |
|---|---|
|
PANiXiDA.Core.Infrastructure.Messaging.Wolverine
Wolverine-based messaging infrastructure adapter for PANiXiDA.Core applications, providing mediator, command, query and event publishing integration. |
|
|
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.