This repository serves as a template and guide for building a Clean Architecture project in C# using ASP.NET Web API. The project structure adheres to the principles of Clean Architecture, separating concerns into distinct layers: Domain, Application, Web API, and Infrastructure.
This layer contains the core business logic and entities of the application. It is independent of any infrastructure or application details. Keep it clean and focus on representing the business rules and behaviors.
The Application layer orchestrates the flow of data between the Domain layer and the Infrastructure layer. It contains use cases, business logic, and application-specific rules. Use the Repository pattern and Unit of Work to interact with the database.
The Web API layer exposes endpoints to interact with the application. It handles incoming HTTP requests, maps them to application use cases, and returns appropriate responses. It uses ASP.NET Web API to provide a RESTful interface.
Infrastructure contains implementation details like databases, external services, and other tools required for the application to function. Use Entity Framework (EF) Core as the ORM for database interactions, SQL Server as the database, and Docker for containerization.
- ASP.NET Core 8.0
- Entity Framework Core
- Docker
- SQL Server
- Xunit (for unit testing)
- JWT for token-based authentication
The project includes a sample API to demonstrate the basic structure and functionality. It can be found in the Web API layer.
Utilize EF Core Migrations to create and update the database schema. Seed the database with initial data using data seeding techniques.
dotnet ef migrations add init --output-dir Infrastructure/Migrations
dotnet ef database update
Implement logging to capture requests and responses for better traceability and debugging.
Include a health check endpoint to monitor the application's overall health and status.
Implement middleware to handle exceptions gracefully, providing meaningful responses to clients.
Use middleware for request validation to ensure that incoming data meets the expected criteria.
Implement basic authentication for user login and registration.
Secure your API with JWT token-based authentication to control access and maintain user sessions.
Write unit tests to ensure the correctness of the application's components.
- Clone the repository
git clone https://github.com/nhonvo/clean-architecture-net-8.0
- Build and run the Docker container
docker-compose up --build
- Access the API
http://localhost:3001/api/{your-endpoints}
Feel free to contribute to this project by submitting issues, feature requests, or pull requests.
This project is licensed under the MIT License.
pack a project command
dotnet new install ./ --force
dotnet pack -o nupkg
dotnet new install ./nupkg/CleanArchitecture.1.0.0.nupkg
dotnet new cleanarch -n MyFirstProject