A production-grade .NET 10 RESTful microservice for managing addresses, built with Clean Architecture, SOLID principles, and Domain-Driven Design.
AddressService/
├── AddressService.Domain/ # Core domain layer
│ ├── Entities/ # Address entity
│ ├── Enums/ # AddressType enum
│ └── Interfaces/ # IAddressRepository, IUnitOfWork
├── AddressService.Application/ # Application layer (use cases)
│ ├── DTOs/ # Request/Response DTOs
│ ├── Mappings/ # AutoMapper profiles
│ ├── Validators/ # FluentValidation rules
│ └── Services/ # Application services
├── AddressService.Infrastructure/ # Data access layer
│ ├── Data/ # DbContext
│ ├── Repositories/ # Repository implementations
│ └── UnitOfWork/ # UnitOfWork pattern
├── AddressService.API/ # Presentation layer
│ ├── Controllers/ # REST endpoints
│ ├── Exceptions/ # Global exception handling
│ ├── Program.cs # Application bootstrap
│ └── appsettings.json # Configuration
└── AddressService.Tests/ # Unit tests
└── Services/ # Service tests (MSTest + Moq)
✅ Clean Architecture - Strict separation of concerns across 5 layers
✅ SOLID Principles - Dependency Injection, Interface Segregation, Single Responsibility
✅ Domain-Driven Design - Address is the core entity
✅ Repository Pattern - Data access abstraction
✅ Unit of Work - Transaction management
✅ Validation - FluentValidation integrated request validation
✅ Logging - Serilog structured logging (console + file)
✅ Error Handling - Global exception handler with RFC 7807 ProblemDetails
✅ API Documentation - Swagger/OpenAPI integration
✅ Unit Tests - MSTest + Moq comprehensive coverage
- .NET 10 SDK
- SQL Server (LocalDB or full instance)
- Visual Studio 2022 or Visual Studio Code
cd c:\Kautilya\Services\AddressService
dotnet new sln -n AddressService
dotnet new classlib -n AddressService.Domain
dotnet new classlib -n AddressService.Application
dotnet new classlib -n AddressService.Infrastructure
dotnet new webapi -n AddressService.API
dotnet new mstest -n AddressService.Tests
# Add projects to solution
dotnet sln add AddressService.Domain/AddressService.Domain.csproj
dotnet sln add AddressService.Application/AddressService.Application.csproj
dotnet sln add AddressService.Infrastructure/AddressService.Infrastructure.csproj
dotnet sln add AddressService.API/AddressService.API.csproj
dotnet sln add AddressService.Tests/AddressService.Tests.csprojcd AddressService.Application
dotnet add reference ../AddressService.Domain/AddressService.Domain.csproj
cd ../AddressService.Infrastructure
dotnet add reference ../AddressService.Domain/AddressService.Domain.csproj
cd ../AddressService.API
dotnet add reference ../AddressService.Domain/AddressService.Domain.csproj
dotnet add reference ../AddressService.Application/AddressService.Application.csproj
dotnet add reference ../AddressService.Infrastructure/AddressService.Infrastructure.csproj
cd ../AddressService.Tests
dotnet add reference ../AddressService.Domain/AddressService.Domain.csproj
dotnet add reference ../AddressService.Application/AddressService.Application.csproj
dotnet add reference ../AddressService.Infrastructure/AddressService.Infrastructure.csproj
dotnet add reference ../AddressService.API/AddressService.API.csprojAddressService.Application:
dotnet add package AutoMapper
dotnet add package FluentValidationAddressService.Infrastructure:
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServerAddressService.API:
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File
dotnet add package Swashbuckle.AspNetCoreAddressService.Tests:
dotnet add package Microsoft.NET.Test.Sdk
dotnet add package MSTest.TestAdapter
dotnet add package MSTest.TestFramework
dotnet add package MoqEdit AddressService.API/appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=YOUR_SERVER;Database=AddressServiceDb;Trusted_Connection=true;Encrypt=false;"
}
}# Restore dependencies
dotnet restore
# Build solution
dotnet build
# Run API
cd AddressService.API
dotnet run
# Run tests
cd ../AddressService.Tests
dotnet test- GET
/api/address- Get all addresses - GET
/api/address/{id}- Get address by ID - POST
/api/address- Create new address - PUT
/api/address/{id}- Update address - DELETE
/api/address/{id}- Delete address
curl -X POST https://localhost:5001/api/address \
-H "Content-Type: application/json" \
-d '{
"streetLine1": "123 Main St",
"city": "New York",
"stateOrProvince": "NY",
"postalCode": "10001",
"country": "USA",
"addressType": 1,
"isDefault": true
}'cd AddressService.API
# Create migration
dotnet ef migrations add InitialCreate --project ../AddressService.Infrastructure
# Apply migration
dotnet ef database update --project ../AddressService.InfrastructureRun unit tests:
dotnet test AddressService.Tests
# With verbose output
dotnet test AddressService.Tests --verbosity detailed
# Filter by category
dotnet test AddressService.Tests --filter "TestCategory=CreateAsync"- Pure, framework-agnostic entities
- No external dependencies
- Clear business logic boundaries
- Use case orchestration
- DTO mapping (AutoMapper)
- Input validation (FluentValidation)
- Transactional integrity
- Entity Framework Core ORM
- Repository pattern implementation
- Unit of Work for transaction management
- Database context configuration
- RESTful controller endpoints
- Global exception handling
- Request/response validation
- Swagger documentation
- Framework: .NET 10
- Database: SQL Server
- ORM: Entity Framework Core 10
- Mapping: AutoMapper 13
- Validation: FluentValidation 11
- Logging: Serilog 4
- Testing: MSTest + Moq
- API Docs: Swagger/OpenAPI
MIT License