NET 9 Clean Architecture Project with Architecture Tests
Complete .NET 9 Clean Architecture Project with Architecture Tests
I've successfully created a complete .NET 9 Clean Architecture project with comprehensive architecture tests based on the examples from the Medium article. Here's what I've delivered:
๐ฆ Project Overview
File: CleanArchitectureWithArchTests.zip
(Ready for download)
The project demonstrates all the architecture testing concepts from the article with a fully functional implementation including:
๐๏ธ Project Structure
The solution contains 5 projects following Clean Architecture principles:
- MyApp.Domain - Core business entities and interfaces
- MyApp.Application - Use cases and application services
- MyApp.Infrastructure - Data access and external services
- MyApp.Web - Web API controllers and presentation layer
- MyApp.Tests.Architecture - Comprehensive architecture tests
โ Architecture Tests Included
Basic Architecture Tests (NetArchTest)
- Domain layer independence verification
- Application layer dependency constraints
- Repository naming convention enforcement
- Domain service interface implementation checks
- Entity immutability validation
- Framework dependency restrictions
Advanced Architecture Tests (ArchUnitNET)
- Detailed dependency analysis
- Entity design pattern enforcement
- Microservice boundary validation
- Use case isolation testing
- Controller dependency verification
๐ Key Features
Complete Implementation: Working User entity with CRUD operations
Dual Testing Frameworks: Both NetArchTest and ArchUnitNET examples
CI/CD Ready: GitHub Actions workflow for automated testing
Production Ready: Proper dependency injection, Entity Framework setup
Documentation: Comprehensive README with usage instructions
Docker Support: Dockerfile for containerization
๐ Files Included (25 total)
Domain Layer
-
User.cs
- Sealed entity with proper encapsulation -
IRepository<T>
- Generic repository interface -
IUserService
- Domain service interface -
UserService
- Domain service implementation
Application Layer
-
CreateUserUseCase
- Use case implementation -
IUserApplicationService
- Application service interface -
UserApplicationService
- Application service implementation
Infrastructure Layer
-
UserRepository
- Repository implementation with EF Core -
AppDbContext
- Entity Framework context -
EmailService
- External service example
Web Layer
-
UsersController
- RESTful API controller -
Program.cs
- Application startup configuration -
appsettings.json
- Configuration settings
Architecture Tests
-
ArchitectureTests.cs
- 12 comprehensive test cases -
AdvancedArchitectureTests.cs
- 8 advanced test scenarios
Configuration
- Solution file with all project references
- Complete
.csproj
files with .NET 9 targeting - CI/CD workflow for GitHub Actions
- Docker configuration
-
.gitignore
for .NET projects
๐ง Getting Started
- Extract the ZIP file
- Open in Visual Studio 2022 or VS Code
-
Run:
dotnet restore
to install dependencies -
Build:
dotnet build
to compile the solution -
Test:
dotnet test MyApp.Tests.Architecture
to run architecture tests -
Run:
dotnet run --project MyApp.Web
to start the API
๐งช Architecture Test Examples
The project includes all the test patterns from the article:
- Layer Independence: Ensures domain doesn't depend on infrastructure
- Dependency Flow: Validates proper inward dependencies
- Naming Conventions: Enforces repository naming patterns
- Interface Implementation: Verifies service contracts
- Entity Design: Ensures entities are sealed and immutable
- Framework Isolation: Prevents unwanted framework dependencies
๐ฏ Benefits
- Immediate Use: Ready-to-run project with working examples
- Learning Tool: Demonstrates Clean Architecture principles
- Quality Assurance: Automated architectural rule enforcement
- Team Adoption: Clear patterns for team development
- Extensible: Easy to add new features while maintaining architecture