dotnet-cqrs/docs/tutorials/README.md

5.5 KiB

Tutorials

Step-by-step tutorials for building applications with Svrnty.CQRS.

Overview

This section provides comprehensive, hands-on tutorials that walk you through building real-world applications using Svrnty.CQRS.

Tutorial Series

Modular Solution

Build a properly structured solution with separated concerns:

  1. Solution Structure - Create project structure (Api, CQRS, Domain, Infrastructure)
  2. Domain Layer - Define entities, value objects, and domain events
  3. CQRS Layer - Implement commands, queries, and handlers
  4. DAL Layer - Set up Entity Framework Core and repositories
  5. API Layer - Configure HTTP and gRPC endpoints
  6. Testing Strategy - Unit and integration testing

What You'll Learn:

  • Multi-project solution architecture
  • Layer separation and dependencies
  • Best practices for code organization
  • Testing strategies for each layer

Prerequisites:

  • .NET 10 SDK
  • Basic understanding of C# and ASP.NET Core

Duration: ~2-3 hours

Event Sourcing

Build an event-sourced application from scratch:

  1. Fundamentals - Event sourcing concepts and benefits
  2. Aggregate Design - Design aggregates and domain events
  3. Events and Workflows - Implement event workflows
  4. Projections - Build read models from events
  5. Snapshots - Optimize with snapshots
  6. Replay and Rebuild - Replay events to rebuild projections

What You'll Learn:

  • Event sourcing pattern
  • Aggregate root design
  • Projection building
  • Event replay
  • Snapshot optimization

Prerequisites:

  • Completed "Getting Started" guide
  • Understanding of domain-driven design
  • PostgreSQL installed

Duration: ~3-4 hours

E-Commerce Example

Build a complete e-commerce order system:

  1. Requirements - Define domain and requirements
  2. Domain Events - Design order lifecycle events
  3. Commands - PlaceOrder, CancelOrder, ShipOrder
  4. Queries - GetOrder, ListOrders, SearchOrders
  5. Projections - Order summaries and analytics
  6. Sagas - Order fulfillment saga
  7. HTTP API - Expose via HTTP endpoints
  8. gRPC API - Expose via gRPC services
  9. Complete Code - Full working implementation

What You'll Learn:

  • Real-world CQRS application
  • Event-driven workflows
  • Saga pattern for distributed transactions
  • Dual HTTP/gRPC endpoints
  • Complete working code

Prerequisites:

  • Completed "Modular Solution" tutorial
  • PostgreSQL installed
  • Understanding of e-commerce domain

Duration: ~4-6 hours

Quick Start Projects

Hello World CQRS

# Create new project
dotnet new webapi -n HelloCQRS
cd HelloCQRS

# Add packages
dotnet add package Svrnty.CQRS
dotnet add package Svrnty.CQRS.MinimalApi

# Create command
# Create handler
# Register services
# Run

See Getting Started for full guide.

Event Streaming Quick Start

# Add event streaming
dotnet add package Svrnty.CQRS.Events.PostgreSQL
dotnet add package Svrnty.CQRS.Events.ConsumerGroups

# Start PostgreSQL
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16

# Configure services
# Publish events
# Consume events

See Event Streaming Getting Started for full guide.

Learning Path

Beginner

  1. Introduction to CQRS
  2. Your First Command
  3. Your First Query
  4. Adding Validation

Intermediate

  1. Modular Solution Tutorial
  2. Dynamic Queries
  3. gRPC Integration

Advanced

  1. Event Sourcing Tutorial
  2. Consumer Groups
  3. Projections and Sagas
  4. E-Commerce Example

Sample Code

All tutorial code is available in the Svrnty.Sample project.

Key Examples:

Community Examples

Share your tutorials and examples:

  • Submit a pull request with your tutorial
  • Link to your blog post or GitHub repo
  • Join the discussion on GitHub

See Also