---
title: ".NET"
description: One folder, one bounded context, in .NET, where it changes the most.
source: dotnet.dh.md
---
<!-- Made by dh llm from the source; nobody edits this file. -->

# .NET

**Possible, and the biggest change of the four.** The layer projects and the solution file go. Each context becomes its own project.

## The files

```filetree
all.proj  # finds projects by pattern; no solution file
kernel/
  Kernel.csproj  # the app
platform/  # what every context may use
guard/  # the layer check, runs in the build
contexts/
  Directory.Build.props  # names and references come from the folder
  orders/
    context.yaml
    contract/
      orders.Contract.csproj
      v1/
    src/
      orders.csproj  # one line
      Context.cs  # the one registration
      api/
        v1/
      mcp/
      domain/
      data/
    policies.yaml
    flags.yaml
    config/
    observability/
    docs/
    tests/
      unit/
      integration/
```

## The boundaries hold

```terminal
$ dotnet build contexts/billing/src/billing.csproj
error CS0234: The type or namespace name 'Orders' does not exist in the namespace 'Ctx' (are you missing an assembly reference?)
$ dotnet build contexts/orders/src/orders.csproj
error LYR001: domain/ imports Microsoft.EntityFrameworkCore (IO or framework)
```

## .NET in detail, on real alcohol.zinc
Two modules were moved into their own projects: Causes (a leaf) and NfcTag (tangled). MEASURED

| Check | Result |
|---|---|
| Build | 0 errors |
| Unit tests | the same 333 names; the same 9 that failed before still fail |
| Database model | byte-identical SQL; no pending migration |
| Files | 164 touched: 109 pure moves, 55 changed |
| Generated registration | no reflection scan |
| Clean build before the move | 18 to 22 s |
| Clean build after the move | 33 s |

- **The pain is the real app, not the template.** In the code, 19 of 23 modules form one loop (this scan folds HabitVersion and HabitExecution into Habit); .NET refuses loops between projects. The shared DbContext is used 506 times in 35 files. MEASURED
- **Your model costs build time:** 25 contexts as projects build in 77 seconds from clean, against 13 seconds as one project. One edit costs about the same (10 against 9 seconds). MEASURED
- I keep projects. They are your model, and they are what makes the compiler guard each context. Caching and testing only the changed context should win most of it back. REASONED, NOT TESTED
- Moving all of zinc: 1 to 2 weeks, mostly untangling the loop. REASONED

## Database models split across projects (EF)

| Question | One DbContext | One DbContext per context |
|---|---|---|
| Model split across projects | works | works |
| Migrations on real Postgres | work | work |
| Two pull requests add neighbouring tables | conflict in the shared snapshot | clean |
| A transaction across contexts | works | needs a shared connection |
| A database link across contexts | works | raw SQL only, invisible to EF |

MEASURED. The design forbids the last two anyway. This is trade-off 2.
