Domain entities and builders for the moclaw project. Provides base entity types and builder interfaces for entity construction and query building.
$ dotnet add package Moclawr.DomainMoclawr.Domain provides essential domain modeling components for building robust business logic layers in .NET applications. It includes base entity classes, builder interfaces, and domain event infrastructure to support Domain-Driven Design (DDD) principles.
dotnet add package Moclawr.Domain
// Create a domain entity with audit tracking
public class Customer : TrackEntity<Guid>
{
public string Name { get; private set; }
public string Email { get; private set; }
public Customer(string name, string email)
{
Name = name;
Email = email;
}
public void UpdateContact(string email)
{
Email = email;
UpdatedAt = DateTime.UtcNow;
}
}
// Implement a fluent builder for an entity
public class CustomerBuilder : IEntityBuilder<Customer>
{
private string _name = string.Empty;
private string _email = string.Empty;
public CustomerBuilder WithName(string name)
{
_name = name;
return this;
}
public CustomerBuilder WithEmail(string email)
{
_email = email;
return this;
}
public Customer Build()
{
return new Customer(_name, _email);
}
}
// Use the fluent query builder
var customers = await repository.GetAllAsync(builder =>
builder
.Where(c => c.IsActive)
.OrderBy(c => c.Name)
.Include(c => c.Orders)
);
Moclawr.Domain is designed to work with:
This project is licensed under the MIT License - see the LICENSE file for details.