DDDAdvisor 1.0.4

dotnet add package DDDAdvisor --version 1.0.4
                    
NuGet\Install-Package DDDAdvisor -Version 1.0.4
                    
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="DDDAdvisor" Version="1.0.4">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DDDAdvisor" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="DDDAdvisor">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 DDDAdvisor --version 1.0.4
                    
#r "nuget: DDDAdvisor, 1.0.4"
                    
#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 DDDAdvisor@1.0.4
                    
#: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=DDDAdvisor&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=DDDAdvisor&version=1.0.4
                    
Install as a Cake Tool

🧠 DDDAdvisor - Roslyn Analyzer

Your personal Domain-Driven Design mentor, right inside your IDE.

DDDAdvisor is a Roslyn analyzer that provides real-time feedback and DDD best practice tips directly in your IDE as you code. Get instant warnings, suggestions, and guidance to help you build better domain models following DDD principles.

NuGet License: MIT

✨ What Does It Do?

DDDAdvisor analyzes your C# code in real-time and provides actionable feedback on:

  • Anemic Entities - Detects entities with no domain behavior (only properties)
  • Mutable Value Objects - Finds value objects that violate immutability
  • Layer Violations - Catches domain depending on infrastructure (DIP violations)
  • Direct Repository Access - Identifies controllers accessing repositories directly
  • Entity Exposure - Warns when domain entities are exposed from API endpoints
  • Large Application Services - Detects services with too many responsibilities

🚀 Installation

NuGet Package Manager

Install-Package DDDAdvisor

.NET CLI

dotnet add package DDDAdvisor

Package Reference

<PackageReference Include="DDDAdvisor" Version="1.0.3" />

That's it! Build your solution and you'll immediately see DDD tips in your IDE.

📖 How It Works

Once installed, DDDAdvisor automatically analyzes your code. Warnings and suggestions appear directly in your IDE (Visual Studio, Visual Studio Code, Rider, etc.).

Example 1: Anemic Entity Detection

❌ Before (Triggers Warning):

// ⚠️ DDD001: Entity 'Customer' contains no domain behavior
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int LoyaltyPoints { get; set; }
}

✅ After (Fixed):

public class Customer
{
    public int Id { get; private set; }
    public string Name { get; private set; }
    public int LoyaltyPoints { get; private set; }

    // Domain behavior added
    public void AddLoyaltyPoints(int points)
    {
        if (points < 0)
            throw new ArgumentException("Points cannot be negative");

        LoyaltyPoints += points;
    }

    public void UpdateName(string newName)
    {
        if (string.IsNullOrWhiteSpace(newName))
            throw new ArgumentException("Name cannot be empty");

        Name = newName;
    }
}

Example 2: Mutable Value Object

❌ Before (Triggers Warning):

// ⚠️ DDD002: Value object 'Money' should be immutable
public class Money
{
    public decimal Amount { get; set; }
    public string Currency { get; set; }
}

✅ After (Fixed):

public class Money
{
    public decimal Amount { get; private set; }
    public string Currency { get; private set; }

    public Money(decimal amount, string currency)
    {
        Amount = amount;
        Currency = currency;
    }

    public Money Add(Money other)
    {
        if (Currency != other.Currency)
            throw new InvalidOperationException("Cannot add money with different currencies");

        return new Money(Amount + other.Amount, Currency);
    }
}

Example 3: Direct Repository Access in Controller

❌ Before (Triggers Error):

// ✗ DDD201: Direct repository access in controller 'OrdersController'
public class OrdersController : ControllerBase
{
    private readonly IOrderRepository _orderRepository;

    public OrdersController(IOrderRepository orderRepository)
    {
        _orderRepository = orderRepository;
    }

    [HttpGet("{id}")]
    public IActionResult Get(int id)
    {
        var order = _orderRepository.GetById(id);
        return Ok(order);
    }
}

✅ After (Fixed):

public class OrdersController : ControllerBase
{
    private readonly IOrderService _orderService;

    public OrdersController(IOrderService orderService)
    {
        _orderService = orderService;
    }

    [HttpGet("{id}")]
    public IActionResult Get(int id)
    {
        var orderDto = _orderService.GetOrderById(id);
        return Ok(orderDto);
    }
}

🎯 Complete Rule Reference

Rule ID Title Severity Description
DDD001 Anemic Entity Warning Entity contains no domain behavior (only properties)
DDD002 Mutable Value Object Warning Value object has settable properties (should be immutable)
DDD003 Missing Aggregate Root Info Entity could be an aggregate root
DDD101 Domain Depends on Infrastructure Error Domain layer references Infrastructure (violates DIP)
DDD102 Circular Dependency Error Circular reference detected between bounded contexts/layers
DDD201 Direct Repository Access Error Controller accesses repository directly (use application service)
DDD202 Entity Exposed from API Warning Domain entity returned from API endpoint (use DTOs)
DDD203 Large Application Service Info Application service has too many responsibilities

⚙️ Configuration

Create a dddadvisor.json file in your solution root to customize analyzer behavior:

{
  "rules": {
    "AnemicEntity": true,
    "MutableValueObject": true,
    "LayerDependencies": true,
    "DirectRepositoryAccess": true,
    "EntityExposedFromApi": true,
    "LargeApplicationService": true
  },
  "severityOverrides": {
    "DDD001": "Warning",
    "DDD002": "Warning",
    "DDD101": "Error",
    "DDD201": "Error"
  },
  "layerMappings": {
    "Domain": ".*Domain.*",
    "Application": ".*Application.*",
    "Infrastructure": ".*Infrastructure.*",
    "Presentation": ".*API.*|.*Web.*|.*Controllers.*"
  },
  "excludePaths": ["**/obj/**", "**/bin/**", "**/Migrations/**"]
}

Configuration Options

  • rules: Enable/disable specific rules
  • severityOverrides: Change severity levels (Error, Warning, Info, Hidden)
  • layerMappings: Define regex patterns to identify your architectural layers
  • excludePaths: Glob patterns for paths to exclude from analysis

Suppressing Warnings

You can suppress warnings using standard .NET attributes:

[System.Diagnostics.CodeAnalysis.SuppressMessage("DDD", "DDD001:Anemic Entity")]
public class Customer
{
    public string Name { get; set; }
}

Or use #pragma directives:

#pragma warning disable DDD001
public class Customer
{
    public string Name { get; set; }
}
#pragma warning restore DDD001

🔧 IDE Integration

Visual Studio

Warnings appear in:

  • Error List window
  • Code editor (green squiggles for suggestions, yellow for warnings)
  • Quick Actions lightbulb (Ctrl+.)

Visual Studio Code

Install the C# extension, and warnings appear in:

  • Problems panel
  • Code editor with squiggles
  • Code Actions lightbulb

JetBrains Rider

Warnings appear in:

  • Problems window
  • Code editor with highlights
  • Alt+Enter quick fixes menu
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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.0.4 143 10/11/2025