Clean Architecture Pattern with .NET Core Web API. BlogWebApi specs can be found here
- Install the latest version of .NET Core SDK .NET Core 3.1
- Install the latest version of Visual Studio Download
- Install the latest version of Docker Docker Desktop
The solution is organized in the following way
- BlogWebApi.WebApi.sln
| - azure-pipelinezz.yml
| - README.md
| - src
| - BlogWebApi.Application
| - BlogWebApi.Domain
| - BlogWebApi.Infrastructure
|- BlogWebApi.WebApi
| - Dockerfile
| - tests
| - Application.UnitTest
| - Infrastructure.IntegrationTests
| - WebApi.EndToEndTests
| -docker-compose
| - docker-compose.yml
This project will include Domain Models, Interfaces that will be implemented by the outside layers, enums, etc., specific to the domain logic. This project should not have any dependecy to another project since it is the core of the project.
- Domain Models (e.g.
Blog) - Interfaces
- Exceptions
- Enums
This project will contain the application logic. The only dependency that should have is the Domain project. Any other project dependency must be removed.
- Exceptions (e.g.:
BadRequestException) - Interfaces (e.g.
IBlogRepository) - DTOs (e.g.:
BlogAddRequestDto) - Mappers (e.g:
BlogMapper)
The Infrastructure project generally includes data access implementations or accessing external resources as file sytems, SMTP, third-party services, etc. These classes should implementations of the Interfaces defined in the Domain Project. Therefore, the only dependency in this project should be to the Domain Project. Any other dependency must be removed.
- EF Core Types (e.g.:
BlogDbContext) - Repository Implementation (e.g.:
BlogRepository)
This is the entry point of our application and it depends on the Application and Infrastrucre projects. The dependency on Infrastructre Project is requiered to support Dependency Injection in the Startup.cs class. Therefore, no direct instantiation of or static calls to the Infrastucture project should be allowed.
- Controllers (e.g.:
BlogsController) - Startup
- Program
- Start debugging using Visual Studio (F5)
- From the root directory, execute the following commands
cd src\BlogWebApi.WebApi
- Build the project
dotnet build BlogWebApi.WebApi.csproj
- Run the project
dotnet run BlogWebApi.WebApi.csproj
dotnet test tests/Application.UnitTest
dotnet test tests/Infrastructure.IntegrationTests
dotnet test tests/WebApi.EndToEndTests
1.From the root folder, execute the following command:
docker-compose -f docker-compose.yml -f docker-compose.override.yml -p BlogWebApi up --build --remove-orphans --abort-on-container-exit
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p P@ssW0rd!
dotnet dev-certs https --trust
dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p P@ssW0rd!
dotnet dev-certs https --trust