It is a simplified approach to implement HTTP APIs, focusing on reducing code and configuration. With just a few lines of code, it is possible to create functional REST endpoints. (Minimal API)
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
Clean Architecture is a software architectural pattern based on the principle of separation of concerns, where the application is divided into different layers, each with its own concern. The goal is to provide developers with a better way to organize code, separating business rules, facilitating development, and code maintenance.
: The Clean Architecture by Robert C. Martin
- Command and Query Responsibility Segregation (CQRS)
- Mediator
- Repository
- Unit of Work
: Minimal API with Clean Architecture
The API is documented using Swagger. By accessing the page, it is possible to test all HTTP requests.
Run the docker compose up --build
command and access http://localhost:8080/swagger
to test the API.
You can also pull the image using the docker pull pedrolucas5100/minimal-api-with-clean-architecture
command and create your own containers.
The
dotnet build
anddotnet run
commands automatically restore dependencies.
- Application
- AutoMapper :
dotnet add package AutoMapper --version 13.0.1
- FluentValidation :
dotnet add package FluentValidation.DependencyInjectionExtensions --version 11.9.0
- MediatR :
dotnet add package MediatR --version 12.2.0
- AutoMapper :
- Persistence
- SQLite :
dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 8.0.4
- SQLite :
- API
- OpenAPI :
dotnet add package Microsoft.AspNetCore.OpenApi --version 8.0.4
- EntityFrameworkCore.Design :
dotnet add package Microsoft.EntityFrameworkCore.Design --version 8.0.0
- Swagger :
dotnet add package Swashbuckle.AspNetCore --version 6.4.0
- OpenAPI :
cd minimal-api-with-clean-architecture/
dotnet build
cd src/Presentation/CleanArchitecture.API
dotnet run
Access: https://localhost:7054/swagger
or http://localhost:5269/swagger
to use Swagger and test the API.
You may need to authorize the use of HTTPS in the local environment. To do this, trust the dotnet https certificate with the following command:
dotnet dev-certs https --trust
- The implementation of the Clean Architecture structure was based on the content from the Jose Carlos Macoratti channel.
- ASP .NET Documentation