Introduction
The Catalog service is a microservice responsible for managing the product catalog in the AspNetRun e-commerce system. It provides a complete CRUD API for products, allowing you to create, read, update, and delete product information.Architecture
Vertical Slice Architecture
The Catalog service implements Vertical Slice Architecture, where each feature is organized in its own folder with all related components:- Endpoint: Defines the HTTP route using Carter
- Handler: Implements business logic using MediatR
- Request/Response: DTOs for API contracts
- Command/Query: CQRS objects for internal operations
- Validator: FluentValidation rules
Technology Stack
Carter
Minimal API routing framework for defining endpoints
MediatR
CQRS implementation with Command/Query handlers
Marten
Document database using PostgreSQL as the backing store
FluentValidation
Declarative validation rules for commands and queries
Key Components
Product Model
The core domain entity representing a product:CQRS Pattern
The service separates read and write operations: Commands (Write operations):CreateProductCommand- Create new productsUpdateProductCommand- Update existing productsDeleteProductCommand- Delete products
GetProductsQuery- Get paginated product listGetProductByIdQuery- Get single product by IDGetProductByCategoryQuery- Get products by category
Middleware Pipeline
The service uses MediatR behaviors for cross-cutting concerns:- ValidationBehavior: Automatic request validation using FluentValidation
- LoggingBehavior: Request/response logging for observability
API Endpoints
The Catalog service exposes the following REST endpoints:| Method | Endpoint | Description |
|---|---|---|
| GET | /products | Get paginated list of products |
| GET | /products/{id} | Get product by ID |
| GET | /products/category/{category} | Get products by category |
| POST | /products | Create new product |
| PUT | /products | Update existing product |
| DELETE | /products/{id} | Delete product |
| GET | /health | Health check endpoint |
Exception Handling
The service implements global exception handling:ProductNotFoundException- Thrown when a product is not found by ID
Health Checks
Health monitoring with PostgreSQL database check:Getting Started
Prerequisites
- .NET 8.0 SDK
- PostgreSQL database
- Docker (optional, for containerized deployment)
Configuration
Configure the database connection inappsettings.json:
Running the Service
http://localhost:5001 (or as configured).
Next Steps
Features
Explore all product management features
API Reference
View detailed API documentation
Database
Learn about Marten and data persistence
Architecture
Deep dive into Vertical Slice Architecture
