Goodtocode.Domain 1.1.22

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

Goodtocode.Domain

Domain-Driven Design (DDD) base library for .NET Standard 2.1 and modern .NET projects.

NuGet CI/CD

Goodtocode.Domain provides foundational types for building DDD, clean architecture, and event-driven systems. It includes base classes for domain entities, audit fields, domain events, and secured/multi-tenant entities. The library is lightweight, dependency-free, and designed to work with EF Core, Cosmos DB, or custom repositories.

Target Frameworks

  • Library: netstandard2.1
  • Tests/examples: net10.0

Features

  • Domain entity base with audit fields (CreatedOn, ModifiedOn, DeletedOn, CreatedBy, ModifiedBy, DeletedBy, Timestamp)
  • Domain event pattern and dispatcher (IDomainEvent, IDomainHandler, DomainDispatcher)
  • Equality and identity management for aggregate roots
  • Partition key support for document stores (PartitionKey)
  • Secured entity base for multi-tenancy and ownership (OwnerId, TenantId)
  • Extension methods for authorization and ownership queries

Install

dotnet add package Goodtocode.Domain

Quick-Start (Repo)

  1. Clone this repository
    git clone https://github.com/goodtocode/aspect-domain.git
    
  2. Build the solution
    cd src
    dotnet build Goodtocode.Domain.sln
    
  3. Run tests
    cd Goodtocode.Domain.Tests
    dotnet test
    

Core Concepts

  • DomainEntity<TModel>: Base entity with audit fields, identity, and domain event tracking.
  • SecuredEntity<TModel>: Adds OwnerId and TenantId, with PartitionKey defaulting to TenantId.ToString().
  • Domain events: Implement IDomainEvent<TModel> and dispatch with DomainDispatcher.

Key Examples

1. Basic Domain Entity with Audit Fields

using Goodtocode.Domain.Entities;

public sealed class MyEntity : DomainEntity<MyEntity>
{
    public string Name { get; private set; } = string.Empty;
    public int Value { get; private set; }

    public static MyEntity Create(Guid id, string name, int value, Guid createdBy)
    {
        var entity = new MyEntity
        {
            Id = id == Guid.Empty ? Guid.NewGuid() : id,
            Name = name,
            Value = value
        };

        entity.SetCreatedOn(DateTime.UtcNow);
        entity.SetCreatedBy(createdBy);

        return entity;
    }
}

2. Secured Entity with Multi-Tenant Ownership

using Goodtocode.Domain.Entities;

public sealed class Document : SecuredEntity<Document>
{
    public string Title { get; private set; } = string.Empty;

    private Document() { }

    public Document(Guid id, Guid ownerId, Guid tenantId, string title)
        : base(id, ownerId, tenantId)
    {
        Title = title;
        SetCreatedOn(DateTime.UtcNow);
        SetCreatedBy(ownerId);
    }
}

// Query helpers
var ownedDocuments = queryableDocuments.WhereOwner(ownerId);
var tenantDocuments = queryableDocuments.WhereTenant(tenantId);
var authorized = queryableDocuments.WhereAuthorized(tenantId, ownerId);

3. Domain Events + Dispatcher

using Goodtocode.Domain.Entities;
using Goodtocode.Domain.Events;

public sealed class Person : SecuredEntity<Person>
{
    public string Email { get; private set; } = string.Empty;

    public Person(Guid id, Guid ownerId, Guid tenantId, string email)
        : base(id, ownerId, tenantId)
    {
        Email = email;
        SetCreatedOn(DateTime.UtcNow);
        AddDomainEvent(new PersonCreatedEvent(this));
    }
}

public sealed class PersonCreatedEvent : IDomainEvent<Person>
{
    public Person Item { get; }
    public DateTime OccurredOn { get; }

    public PersonCreatedEvent(Person person)
    {
        Item = person;
        OccurredOn = DateTime.UtcNow;
    }
}

public sealed class PersonCreatedHandler : IDomainHandler<PersonCreatedEvent>
{
    public Task HandleAsync(PersonCreatedEvent domainEvent)
    {
        Console.WriteLine($"Created: {domainEvent.Item.Email}");
        return Task.CompletedTask;
    }
}

// Dispatcher usage (with your DI container)
var serviceProvider = new ServiceCollection()
    .AddTransient<IDomainHandler<PersonCreatedEvent>, PersonCreatedHandler>()
    .BuildServiceProvider();

var dispatcher = new DomainDispatcher(serviceProvider);
await dispatcher.DispatchAsync(person.DomainEvents);
person.ClearDomainEvents();

Complete Examples

See the fully working examples in the test project:

  • Goodtocode.Domain.Tests/Examples/RowLevelSecurityExample.cs (row-level security, audit fields, and partition key usage)
  • Goodtocode.Domain.Tests/Examples/CommandHandlerWithEventsExample.cs (command handlers, domain events, dispatcher, and service bus integration)

Technologies

Version History

Version Date Release Notes
1.0.0 2026-Jan-19 Initial release

License

This project is licensed with the MIT license.

Contact

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.24 31 2/14/2026
1.1.22 36 2/14/2026
1.1.20 33 2/14/2026
1.1.13 33 2/10/2026
1.1.11 43 2/10/2026
1.1.8 94 2/8/2026
1.1.6 245 1/21/2026
1.1.4 81 1/23/2026
1.1.3 86 1/20/2026