This project demonstrates a production-ready implementation of a weather forecast service using .NET Aspire with real-world requirements and best practices.
- Full CRUD Operations: Complete REST API for weather forecasts
- Health Checks: Comprehensive health monitoring
- API Documentation: Swagger UI, ReDoc, and Scalar integration
- Containerization: Docker support for deployment
- Observability: OpenTelemetry integration
- Resilience: Built-in resilience patterns
- Service Discovery: Automatic service discovery
- CORS Support: Cross-origin resource sharing configuration
- Response Compression: Optimized payload delivery
- Configuration Management: Environment-specific settings
├── ApiService/
│ ├── Controllers/ # API controllers
│ ├── Models/ # Data models
│ ├── Services/ # Business logic services
│ ├── Program.cs # Application entry point
│ └── Dockerfile # Container definition
├── Aspire.Customization.AppHost/
│ ├── Program.cs # Aspire application host
│ └── ResourceBuilderExtensions.cs
└── Aspire.Customization.ServiceDefaults/
└── Extensions.cs # Shared service configurations
GET /api/weatherforecast- Get all weather forecastsGET /api/weatherforecast/{date}- Get a specific weather forecastPOST /api/weatherforecast- Create a new weather forecastPUT /api/weatherforecast/{date}- Update an existing weather forecastDELETE /api/weatherforecast/{date}- Delete a weather forecast
GET /health- Application health statusGET /alive- Liveness probeGET /swagger- Swagger UI documentationGET /scalar/v1- Scalar API referenceGET /api-docs- ReDoc documentation
- .NET 9 SDK
- Docker (optional, for containerization)
-
Using .NET CLI:
cd Aspire.Customization.AppHost dotnet run -
Using Docker:
docker-compose up
The project follows clean architecture principles with separation of concerns:
- Controllers: Handle HTTP requests and responses
- Services: Implement business logic
- Models: Define data structures
- Extensions: Provide reusable functionality
The application supports multiple environments through configuration files:
appsettings.json- Base configurationappsettings.Development.json- Development environmentappsettings.Production.json- Production environment (if created)
Key configuration sections include:
- ApiSettings: API metadata
- HealthCheckSettings: Health monitoring configuration
- CorsSettings: Cross-origin resource sharing settings
The application can be containerized using the provided Dockerfile:
# Build the image
docker build -t weather-api -f ApiService/Dockerfile .
# Run the container
docker run -p 8080:8080 weather-apiThe Aspire application host provides orchestration capabilities for deploying the entire solution with dependent services.
- Error Handling: Comprehensive exception handling with proper HTTP status codes
- Logging: Structured logging with appropriate levels
- Documentation: XML documentation for all public APIs
- Health Monitoring: Custom health checks with detailed reporting
- Security: HTTPS enforcement and CORS configuration
- Performance: Response compression and caching considerations
- Resilience: Retry policies and circuit breaker patterns
- Observability: OpenTelemetry integration for metrics and tracing
To add new features:
- Create a new model in the
Modelsfolder - Define a service interface in the
Servicesfolder - Implement the service
- Create a controller to expose the functionality
- Register the service in
Program.cs - Add appropriate tests
This project demonstrates enterprise-grade development practices. Contributions should follow the established patterns and include appropriate tests.
This project is a demonstration and educational resource.