The following solution template can be used for creating C# ASP .NET Core WebAPI using Clean Architecture Design Pattern Principles.
- ASP .NET Core 3.1
- MediatR
- FluentValidation
- FluentAssertions
- Moq
- Docker
- Lorem.Universal.NET
- Newtonsoft.Json
- xUnit
- Swashbuckle.AspNetCore
- Install Visual Studio
- Install the latest .NET 5 SDK | .NET 6 SDK
- Install .Net Core 3.1 SDK.
- Clone this repository in your computer in a local
<DIRECTORY>
(e.g.: C:\Users\hack3rlife\source\repos
). - Install the template by running the following command:
dotnet new <DIRECTORY>
. - Create a new directory (
e.g.: hack3rlife-cleanarchitecture
) andcd
into it. - Create a new solution by executing the following command
dotnet new -i CleanArchitectureNetCoreWebAPI -n <PROJECT_NAME>
.
- Execute
dotnet new -i Hack3rlife.ASP.NETCore.WebAPI
to install the latest version.- Execute
dotnet new -u Hack3rlife.ASP.NETCore.WebAPI
to uninstall the template.
- Execute
The solution is organized in the following way
- BlogWebApi.WebApi.sln
| - README.md
| - src
| - BlogWebApi.Application
| - BlogWebApi.Domain
| - BlogWebApi.Infrastructure
|- BlogWebApi.WebApi
| - tests
| - Application.UnitTest
| - Infrastructure.IntegrationTests
| - WebApi.EndToEndTests
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
- 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
- Interfaces
- DTOs
- Mappers
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
- Repository Implementation
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
- Startup
- Program