This project provides a fully functional example of a .NET 8 API built with the Mediator Design Pattern. It demonstrates best practices for handling exceptions, validating requests, and logging through middleware, filters, and behaviors.
- Uses SQLite as a lightweight relational database
- Middleware for centralized exception handling (see ExceptionMiddlewareExtensions)
- Action Filters for validation and consistent API responses (see ValidateModelStateAttribute and ApiResponseAttribute)
- Mediator Behaviors for logging actions before and after handler execution (see LoggingBehavior)
- .NET 8 SDK
- SQLite (no additional setup needed, SQLite is file-based)
-
Build the project:
dotnet build
-
Start the application:
-
Option 1: Use debug mode in your IDE.
-
Option 2: Run the application from the /src folder:
dotnet run
-
Apply Database Migrations (if needed): To ensure the SQLite database is up-to-date, apply any pending migrations:
dotnet ef database update
-
Run the following command in
MediatrSampleApi.UnitTest
folder:dotnet test
- FluentValidation - Library for building strongly-typed validation rules.
- AutoMapper - A convention-based object-object mapper in .NET
- Mediatr - mediator implementation in .NET
- Swashbuckle - adds a swagger to WebApi projects
- Entity Framework
- FluentAssertions - Fluent API for asserting the results of unit tests that targets
- MyTested - Fluent testing library for ASP.NET Core MVC
- AutoFixture - Auto-generates test data.
- Moq - Mocking library for .NET.