Skip to content

Build a Library with Deepstaging

You're going to build a library management system — two separate contexts that talk to each other through events, with a REST API, background jobs, full-text search, and tests. Everything runs in-memory. No database, no message broker, no Docker. Just dotnet run.

What You'll Build

Two contexts, a shared contracts project, and a test project:

Library/
├── src/
│   ├── Library.Contracts/     # Shared IDs and integration events
│   ├── Library.Catalog/       # Books, authors, search
│   └── Library.Lending/       # Patrons, loans, holds, overdue checks
└── test/
    └── Library.Tests/         # Tests for both contexts
┌──────────┐   integration    ┌──────────┐
│ Catalog  │◄──── events ────►│ Lending  │
└──────────┘                  └──────────┘
       ▲                            ▲
       └────── Library.Contracts ───┘

Catalog knows about books. Lending knows about patrons and loans. When someone borrows a book, Lending tells Catalog to update the inventory. They never reference each other directly — just events flowing through Contracts.

Chapters

# Chapter What You'll Learn What You'll Build
1 Project Setup [TypedId], [StoredEntity], [DataStore] IDs, Book entity, CatalogStore
2 Effects & Runtime [Runtime], Eff<RT,T>, testing CatalogRuntime, first test
3 Commands & Queries [DispatchModule], validation, search AddBook, SearchBooks
4 Adding a REST API [RestApi], [RateLimit], OpenAPI Catalog endpoints
5 The Lending Context Second runtime, [Idempotent] BorrowBook, ReturnBook
6 Domain Events [EventQueue], in-process events Loan count tracking
7 Jobs [BackgroundJob], [Schedule] Overdue loan checker
8 Integration Events [IntegrationEvents], cross-context flow Inventory sync
9 What's Next Where to go from here

Tests are part of development

Each chapter includes tests as you go — not bolted on at the end.

Prerequisites

  • .NET 10 SDK
  • An IDE — Visual Studio, Rider, or VS Code with C# Dev Kit
  • Basic familiarity with C# and dependency injection

That's it. No Docker. No cloud accounts. No infrastructure.

The Pattern

Every Deepstaging feature works the same way:

Attribute → Source Generator → Generated C# → Compiled into your app

No reflection. No runtime magic. Everything the generator produces is visible in your generated/ folder — you can read it, debug into it, and navigate it in your IDE.

Reference implementation

The complete working code lives in the Library sample. Use it to check your work or skip ahead.

Get started → Project Setup