WeatherSample: A Modern .NET 8 Weather Forecasting Demo App
Explore this well-structured multi-project solution leveraging modern .NET 8 features and best practices for scalability and maintainability. The code started with .NET Aspire starter template and went on to include EF & SQLExpress and Controller etc. to build foundations for Enterprise MVC API-driven application. With API-first design, the frontend can be re-written in React or Angular easily - highly decoupled. Have you seen the Kendo UI toolkit?
The WeatherSample solution follows a layered architecture with clear separation of concerns, built on .NET 8 using C# 12.0. This design promotes scalability, maintainability, and testability.
Presentation Layer
Blazor WebAssembly front-end
Service Layer
ASP.NET Core Web API
Data Access Layer
Repository Pattern with EF Core
Front-End: WeatherSample.Web
The front-end is built using Blazor WebAssembly, providing an interactive user interface for displaying weather forecasts. It communicates with the back-end API to fetch and display data.
Weather.razor
Razor component responsible for rendering weather data in an interactive and user-friendly format.
WeatherApiClient.cs
Client service that handles all communication with the back-end API, managing HTTP requests and responses.
Interactive UI
Leverages Blazor's component-based architecture for a responsive and dynamic user experience.
Back-End: WeatherSample.ApiService
The back-end is an ASP.NET Core Web API that manages weather forecasts, providing endpoints for retrieving and creating forecast data. It implements validation, configuration, and dependency injection.
API Endpoints
GET and POST endpoints for weather forecast data
Validation
FluentValidation for validating incoming DTOs
Configuration
Object mapping and application settings
Dependency Injection
Logging, feature management, and repositories
Data Access: WeatherSample.Repository
The repository layer handles data access using Entity Framework Core, implementing the Repository Pattern to abstract database operations and provide a clean interface for the API service.
WeatherDbContext
Entity Framework Core DbContext that manages database connections and entity configurations.
WeatherRepository
Implementation of IWeatherRepository interface providing CRUD operations for weather forecast data.
Entities
WeatherForecast entity representing the database model for storing forecast information.
Shared Components: WeatherSample.ServiceDefaults
The ServiceDefaults project contains shared DTOs and utilities used across the solution, promoting code reuse and maintaining consistency between layers.
Data Transfer Objects
WeatherForecastDto provides a consistent contract for data exchange between layers.
Utilities
Shared helper methods and extension classes used throughout the solution.
Interface Definitions
Common interfaces establishing contracts between different layers of the application.
Testing: WeatherSample.ApiService.Tests
The solution includes comprehensive unit tests for the API service, ensuring reliability and correctness of the application logic.
Controller Tests
Validates that the WeatherForecastController returns appropriate responses for different scenarios.
Validation Tests
Ensures that input validation correctly identifies invalid data and prevents processing.
Mocking
Uses Moq to create mock implementations of dependencies for isolated testing.
Edge Cases
Tests boundary conditions and error handling to ensure robustness.
Key Technologies and Design Patterns
The solution leverages modern technologies and established design patterns to create a robust, maintainable application.