Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 4.19 KB

README.en.md

File metadata and controls

84 lines (62 loc) · 4.19 KB

Minimal API with Clean Architecture

C# ASP .NET SQLite Docker

Minimal API

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

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 : The Clean Architecture by Robert C. Martin

Used Patterns

  • Command and Query Responsibility Segregation (CQRS)
  • Mediator
  • Repository
  • Unit of Work

How is the dependency between projects implemented in this solution?

layers diagram : Minimal API with Clean Architecture

Testing the Project

The API is documented using Swagger. By accessing the page, it is possible to test all HTTP requests.

Docker

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.

Local Test

Prerequisites:

Used Packages

The dotnet build and dotnet 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
  • Persistence
    • SQLite : dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 8.0.4
  • 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

Build

cd minimal-api-with-clean-architecture/
dotnet build

Run

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

References

License

License