Introduction
AspNetRun Microservices is a reference application demonstrating modern .NET microservices architecture patterns. The project showcases multiple architectural approaches, allowing you to choose the pattern that best fits your domain complexity.Architecture Patterns
This project implements three distinct architectural patterns across different services:Clean Architecture + DDD
Used in Ordering service for complex business domains
Vertical Slice
Used in Catalog service for simpler CRUD operations
CQRS Pattern
Applied across all services for separating reads and writes
System Architecture
Service Breakdown
Catalog Service
Pattern: Vertical Slice ArchitectureDatabase: PostgreSQL with Marten (Document DB)Location:
src/Services/Catalog/Catalog.API- Simple domain model without complex business rules
- Feature-based organization
- Minimal ceremony for CRUD operations
Ordering Service
Pattern: Clean Architecture + Domain-Driven DesignDatabase: SQL Server with Entity Framework CoreLocation:
src/Services/Ordering/- Layered architecture (Domain, Application, Infrastructure, API)
- Rich domain models with entities, value objects, and aggregates
- Domain events for side effects
- Separation of concerns with clear dependencies
Basket Service
Pattern: Simple CQRSDatabase: Redis for distributed cachingLocation:
src/Services/Basket/Basket.APIDiscount Service
Pattern: gRPC ServiceDatabase: SQLiteLocation:
src/Services/Discount/Discount.GrpcCross-Cutting Concerns
BuildingBlocks
Thesrc/BuildingBlocks directory contains shared abstractions and implementations used across all services:
- CQRS Abstractions:
ICommand,IQuery,ICommandHandler,IQueryHandler - Behaviors: Logging, Validation, and other cross-cutting concerns
- Messaging: Integration event definitions and MassTransit configuration
- Exception Handling: Custom exception types and global handlers
- Pagination: Reusable pagination contracts
API Gateway
The project uses YARP (Yet Another Reverse Proxy) as a lightweight, high-performance API gateway:- Routes external requests to appropriate microservices
- Provides a single entry point for clients
- Handles cross-cutting concerns like CORS
src/ApiGateways/YarpApiGateway
Communication Patterns
Synchronous Communication
- HTTP/REST: Client-to-service and service-to-service via API Gateway
- gRPC: High-performance inter-service communication (Basket → Discount)
Asynchronous Communication
- Message Broker: RabbitMQ with MassTransit
- Integration Events:
BasketCheckoutEventpublished when checkout occurs - Event Handlers: Ordering service subscribes to basket events
Design Principles
Separation of Concerns
Separation of Concerns
Each service is independent with its own database, allowing teams to work autonomously and deploy independently.
Single Responsibility
Single Responsibility
Services are focused on specific business capabilities (Catalog, Ordering, Basket).
Dependency Inversion
Dependency Inversion
High-level modules don’t depend on low-level modules. Both depend on abstractions (interfaces).
Domain-Driven Design
Domain-Driven Design
Complex domains (Ordering) use tactical DDD patterns: Aggregates, Entities, Value Objects, Domain Events.
Technology Stack
| Category | Technology |
|---|---|
| Framework | .NET 8 |
| API Style | Minimal APIs with Carter |
| Mediator | MediatR for CQRS |
| Validation | FluentValidation |
| ORM | Entity Framework Core, Marten |
| Databases | SQL Server, PostgreSQL, Redis, SQLite |
| Messaging | RabbitMQ with MassTransit |
| API Gateway | YARP |
| Mapping | Mapster |
| Containerization | Docker |
When to Use Each Pattern
Use Clean Architecture + DDD When:
- Complex business logic and rules
- Rich domain models
- Long-lived projects
- Multiple teams
- Domain events needed
Use Vertical Slice When:
- Simple CRUD operations
- Small to medium projects
- Rapid development needed
- Minimal business logic
- Quick iterations
Next Steps
Explore Microservices Pattern
Learn about microservices principles and implementation
Study Clean Architecture
Deep dive into the Ordering service architecture
Understand DDD
Learn Domain-Driven Design tactical patterns
CQRS Implementation
See how CQRS is implemented across services
