Skip to content

beyondnetcode/Shell.ddd

Repository files navigation

BeyondNet.Ddd

A Domain-Driven Design (DDD) library for .NET

🇬🇧 English | 🇪🇸 Español

NuGet Build


Welcome to BeyondNet.Ddd! A library for implementing Domain-Driven Design patterns in .NET with clean, maintainable code.

Installation

NuGet Packages

# Core DDD library
dotnet add package BeyondNetCode.Shell.Ddd

# Value Objects
dotnet add package BeyondNetCode.Shell.Ddd.ValueObjects

# AutoMapper integration
dotnet add package BeyondNetCode.Shell.Ddd.AutoMapper

Packages Overview

Package Description NuGet
BeyondNetCode.Shell.Ddd Core DDD abstractions (Entity, AggregateRoot, DomainEvents, Rules) link
BeyondNetCode.Shell.Ddd.ValueObjects Pre-built value objects (IdValueObject, AuditValueObject, Validators) link
BeyondNetCode.Shell.Ddd.AutoMapper AutoMapper integration for DDD entities link

Features

  • Entity Base Class: Full-featured entity implementation with tracking, validation, and business rules
  • Aggregate Root: Specialized entity for aggregate roots with domain events support
  • Value Objects: Immutable value objects with built-in validation
  • Business Rules: Rule engine with BrokenRulesManager for domain validation
  • Property Change Tracking: INotifyPropertyChanged implementation with change tracking
  • AutoMapper Integration: Seamless mapping between DTOs and domain entities
  • MediatR Integration: Built-in support for domain events via MediatR

Quick Start

Define an Entity

public class SampleName : ValueObject<SampleName>
{
    public string Value { get; }

    public SampleName(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentNullException(nameof(value));

        Value = value;
    }

    protected override IEnumerable<object> GetEqualityComponents()
    {
        yield return Value;
    }
}

public class SampleEntityProps : IProps
{
    public SampleName Name { get; set; }
}

public class SampleEntity : Entity<SampleEntity, SampleEntityProps>
{
    public SampleEntity(SampleEntityProps props) : base(props)
    {
    }

    public static SampleEntity Create(string name)
    {
        var props = new SampleEntityProps { Name = new SampleName(name) };
        return new SampleEntity(props);
    }

    public override void AddValidators()
    {
        ValidatorRules.Add(new SampleNameValidator());
    }
}

Define an Aggregate Root with Domain Events

public class SampleCreatedDomainEvent : DomainEvent
{
    public Guid EntityId { get; }
    public string Name { get; }

    public SampleCreatedDomainEvent(Guid entityId, string name)
    {
        EntityId = entityId;
        Name = name;
    }
}

public class SampleAggregateRootProps : IProps
{
    public SampleName Name { get; set; }
}

public class SampleAggregateRoot : AggregateRoot<SampleAggregateRoot, SampleAggregateRootProps>
{
    public SampleAggregateRoot(SampleAggregateRootProps props) : base(props)
    {
    }

    public static SampleAggregateRoot Create(string name)
    {
        var props = new SampleAggregateRootProps { Name = new SampleName(name) };
        var entity = new SampleAggregateRoot(props);
        entity.DomainEvents.Add(new SampleCreatedDomainEvent(entity.Id.Value, name));
        return entity;
    }
}

Use with AutoMapper

// Configure AutoMapper
var config = new MapperConfiguration(cfg =>
{
    cfg.AddProfile<ParentRootProfile>();
});
var mapper = new Mapper(config);

// Map DTO to Entity
var dto = new SampleEntityDto { Id = "1", Name = "test" };
var props = mapper.Map<SampleEntityProps>(dto);
var entity = new SampleEntity(props);

Documentation

For detailed documentation, see the language-specific README files:

Migration from Ums.Shell.Ddd

If you were using Ums.Shell.Ddd, update your NuGet references:

# Before (Ums.Shell.Ddd)
dotnet add package Ums.Shell.Ddd

# After (BeyondNetCode.Shell.Ddd)
dotnet add package BeyondNetCode.Shell.Ddd

Update namespaces in your code:

// Before
using Ums.Shell.Ddd;

// After
using BeyondNetCode.Shell.Ddd;

Contributing

See CONTRIBUTING.md for GitFlow workflow, commit conventions, and coding standards.

Versioning

See VERSIONING.md for SemVer strategy and release process.

License

Licensed under the MIT License. See LICENSE for details.

Acknowledgments

See DISCLAIMER.md for original code authorship attribution.

About

Domain-Driven Design library for .NET with entities, aggregate roots, value objects, domain events, business rules, and AutoMapper support.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages