- Home
- .NET code examples
- Clean architecture in a Web API endpoint
Clean architecture in a Web API endpoint
Learn how to use clean architecture in an ASP.NET Core Web API endpoint using validation, services and repositories.
You can learn more about clean architecture in .NET, or watch the video.
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
Software
This is the software that will need to be installed onto your machine.
Visual Studio 2026. Version 18.0.0 or above. It will work with the free community version.
.NET 10 SDK. Version 10.0.0 or above.
Import the database
This application integrates with a SQL Server database. Inside the Database folder, there is RoundTheCode_CleanArchitecture.bacpac and RoundTheCode_CleanArchitecture.bak. Use either of these database backups to import the database to your local SQL Server database server.
The application
Inside Api/appsettings.Development.json, find ConnectionStrings > CleanArchitectureDbContext and point the connection string to your imported database.
Open up RoundTheCode.CleanArchitecture.slnx, and run the application. The Swagger documentation will load at https://localhost:7411/swagger with this endpoint:
/api/products (POST)- Adds a product to the database
Reset data
To reset [dbo].[Products], run ResetProducts.sql inside the Database folder against your database. This will empty [dbo].[Products].
Latest code examples