[go: up one dir, main page]

Skip to content

Clean Architecture Project Template for ASP .NET Core WebAPI Projects using C#

License

Notifications You must be signed in to change notification settings

hack3rlife/cleanarchitecture-webapi-template

Repository files navigation

Clean Architecture Template

The following solution template can be used for creating C# ASP .NET Core WebAPI using Clean Architecture Design Pattern Principles.

Frameworks, tools and techologies used

  1. ASP .NET Core 3.1
  2. MediatR
  3. FluentValidation
  4. FluentAssertions
  5. Moq
  6. Docker
  7. Lorem.Universal.NET
  8. Newtonsoft.Json
  9. xUnit
  10. Swashbuckle.AspNetCore

Index

Getting Started

  1. Install Visual Studio
  2. Install the latest .NET 5 SDK | .NET 6 SDK
  3. Install .Net Core 3.1 SDK.

Local Installation

  1. Clone this repository in your computer in a local <DIRECTORY> (e.g.: C:\Users\hack3rlife\source\repos).
  2. Install the template by running the following command: dotnet new <DIRECTORY>.
  3. Create a new directory (e.g.: hack3rlife-cleanarchitecture) and cd into it.
  4. Create a new solution by executing the following command dotnet new -i CleanArchitectureNetCoreWebAPI -n <PROJECT_NAME>.

NuGet Installation

  1. Execute dotnet new -i Hack3rlife.ASP.NETCore.WebAPI to install the latest version.
    1. Execute dotnet new -u Hack3rlife.ASP.NETCore.WebAPI to uninstall the template.

How the code is organized

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

Domain Project

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 Types

  • Domain Models
  • Interfaces
  • Exceptions
  • Enums

Application Project

This project will contain the application logic. The only dependency that should have is the Domain project. Any other project dependency must be removed.

Appllication Types

  • Exceptions
  • Interfaces
  • DTOs
  • Mappers

Infrastructure Project

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.

Infrastructure Types

  • EF Core Types
  • Repository Implementation

WebAPI Project

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.

WebAPI Types

  • Controllers
  • Startup
  • Program

References