Welcome to the Clean Architecture Mini-Workshop! In this hands-on workshop, you'll learn how to transform a tightly coupled, monolithic ASP.NET Core application into a well-structured Clean Architecture solution.
Time Estimate: 2 hours
By the end of this workshop, you will be able to:
- Identify common architectural problems in tightly coupled applications
- Install and use the Ardalis Clean Architecture template
- Implement features using vertical slice architecture
- Apply CQRS patterns with Mediator
- Properly separate concerns across architectural layers
- Apply dependency injection and inversion of control principles
- .NET 10 SDK installed
- Visual Studio 2022 or VS Code with C# extension
- Basic understanding of ASP.NET Core MVC
- Familiarity with Entity Framework Core
The legacy/TightlyCoupled.WebShop application is a deliberately poorly designed e-commerce application that exhibits many anti-patterns:
- Hard-coded paths and configuration throughout the codebase
- Static utility classes that violate dependency injection principles
- Mixed concerns - business logic, data access, and infrastructure all intertwined
- Direct file system and database access in controllers
- No abstractions - concrete implementations everywhere
- Poor testability - tightly coupled to external dependencies
- Global state - shared mutable state across the application
Your mission is to migrate this application to Clean Architecture!
This workshop follows a vertical slice approach - instead of building entire layers at once, we'll implement complete features from UI to database one at a time. This mirrors real-world development and shows the full power of Clean Architecture.
Time: 15 minutes
Install the Ardalis Clean Architecture template and create a new solution structure. Explore the layers and understand the dependency rules.
You will:
- Install the Clean Architecture template
- Generate a new solution (which creates its own
srcfolder structure) - Understand the Core, UseCases, Infrastructure, and Web layers
- Learn the dependency inversion principle
Time: 30 minutes
Implement your first complete feature - listing available items in the catalog. You'll work through all layers: domain model → repository → query → API endpoint.
You will:
- Create the
Itementity in Core - Define repository interfaces
- Implement the repository in Infrastructure
- Create a "List Items" query with Mediator
- Build an API endpoint in the Web layer
- Test the complete feature end-to-end
Time: 40 minutes
Build a more complex feature with business logic - placing an order. This introduces aggregates, domain events, and command handlers.
You will:
- Create the
Orderaggregate with business rules - Implement a "Place Order" command
- Handle order validation
- Configure entity relationships in Infrastructure
- Create an API endpoint for order placement
- Add unit tests for the command handler
Time: 25 minutes
Identify and replace anti-patterns from the legacy application. Learn how to properly handle cross-cutting concerns.
You will:
- Replace static utility classes with dependency injection
- Move hard-coded configuration to the Options pattern
- Implement proper logging with ILogger
- Create abstractions for external services
- Compare testability: legacy vs. clean architecture
Time: 10 minutes + Bonus Challenges
Wrap up with testing strategies, deployment considerations, and bonus challenges.
You will:
- Write integration tests
- Understand migration strategies for real applications
- Review SOLID principles in practice
- Explore bonus challenges (Specifications, FluentValidation, Domain Events)
This workshop uses vertical slice architecture rather than building layer-by-layer. Here's why:
- Build all domain entities
- Build all repositories
- Build all use cases
- Build all endpoints
Problems:
- Can't test anything until all layers are done
- Lose sight of actual features
- Harder to understand dependencies
- Doesn't match real development flow
- Pick a feature (e.g., "List Items")
- Build entity → repository → query → endpoint for that feature
- Test the complete feature
- Move to next feature
Benefits:
- Working feature after each slice
- Clear understanding of data flow
- Easier to test and validate
- Matches agile development practices
- Demonstrates Clean Architecture patterns in context
Ready to begin? Head over to Lab 1: Setup and Template Installation to get started!
- Ardalis Clean Architecture Template
- Clean Architecture by Robert C. Martin
- Vertical Slice Architecture
- Mediator Documentation
- Ardalis Result Pattern
Need help? Ask your instructor or refer to the solution branch in the repository.