Shared domain primitives and base entities for applications. Provides base classes for entities, aggregate roots, and domain events following Domain-Driven Design principles.
$ dotnet add package DomainCoreDomain primitives, base entities, aggregate roots, and domain events for building Domain-Driven Design applications with .NET.
dotnet add package DomainCore
BaseEntity with Id, ExternalId, and audit fieldsBaseTenantEntity for multi-tenant applicationsIAggregateRoot marker interfaceDomainEventBase and HasDomainEventsBase for event-driven designCreatedAt, CreatedBy, UpdatedAt, UpdatedBy trackingusing DomainCore.Entities;
public class Product : BaseEntity
{
public string Name { get; set; }
public decimal Price { get; set; }
public Product(string name, decimal price, Guid userId)
{
Name = name;
Price = price;
SetUser(userId);
}
}
using DomainCore.Entities;
public class Order : BaseTenantEntity
{
public Guid ProductId { get; set; }
public int Quantity { get; set; }
public decimal TotalPrice { get; set; }
public Order(Guid productId, int quantity, decimal totalPrice, Guid tenantId, Guid userId)
{
ProductId = productId;
Quantity = quantity;
TotalPrice = totalPrice;
SetTenant(tenantId);
SetUser(userId);
}
}
using DomainCore.Events;
public class OrderPlacedEvent : DomainEventBase
{
public Guid OrderId { get; }
public decimal TotalAmount { get; }
public OrderPlacedEvent(Guid orderId, decimal totalAmount)
{
OrderId = orderId;
TotalAmount = totalAmount;
}
}
public class Order : BaseTenantEntity
{
public void Place()
{
// Business logic...
IsPlaced = true;
UpdateTimestamp();
// Raise domain event
RegisterDomainEvent(new OrderPlacedEvent(ExternalId, TotalPrice));
}
}
Provides common entity properties:
Guid Id - Internal database IDGuid ExternalId - Public-facing UUIDDateTime CreatedAt - Creation timestampGuid? CreatedBy - User who created the entityDateTime? UpdatedAt - Last update timestampGuid? UpdatedBy - User who last updated the entityExtends BaseEntity with multi-tenancy:
Guid TenantId - Tenant identifier for data isolationvoid SetTenant(Guid tenantId) - Set the tenant IDFor entities that raise domain events:
List<DomainEventBase> DomainEvents - Collection of eventsvoid RegisterDomainEvent(DomainEventBase domainEvent) - Add eventvoid ClearDomainEvents() - Clear all eventsContributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
cd C:\desktopContents\projects\SaaS\NuGetPackages\DomainCore
.\publish.ps1 -ApiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Bump patch # Bug fixes
.\publish.ps1 -ApiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Bump minor # New features
.\publish.ps1 -ApiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Bump major # Breaking changes