Overview
The Shared.Application module contains common application-layer abstractions and utilities used across all business modules. It provides base DTOs, caching infrastructure, and shared interfaces.Components
Base DTOs
Common data transfer objects used across modules:BaseDto
Dto/BaseDto.cs
Common DTOs
Pagination DTOs
Caching
IAppCache Interface
Interfaces/IAppCache.cs
AppCache Implementation (Redis)
Caching/AppCache.cs
Usage Example
Services/CategoryService.cs (from Catalog module)
Configuration
Dependency Injection
Extensions/DependencyInjection.cs
Redis Configuration
appsettings.json
Program.cs
Caching Strategies
Cache-Aside Pattern
TheGetOrCreateAsync method implements the cache-aside pattern:
- Check if data exists in cache
- If found, return cached data
- If not found, fetch from source (database)
- Store in cache for future requests
- Return data
Cache Invalidation
When data changes, invalidate the cache:Services/CategoryService.cs
Common DTO Patterns
Request DTOs
Input models for API endpoints:Response DTOs
Output models returned from services:Update DTOs
Partial update models:Best Practices
Cache Key Naming
Use descriptive, hierarchical keys:
"module:entity:operation" (e.g., "catalog:categories:all_parents")Expiration Times
Set appropriate expiration based on data volatility - frequently changing data gets shorter TTL
DTO Validation
Use FluentValidation or DataAnnotations for DTO validation at the API boundary
Mapping
Keep mapping logic in dedicated mapper classes or extension methods
Related Modules
- Shared.Domain - DTOs often map to/from domain entities and value objects
- All Business Modules - All modules use shared DTOs and caching infrastructure