ASP.Net 8 API template with CQRS, EF, unit tests, integration tests with TestContainers and more
- Install it using
dotnet new
dotnet new install morasiuapi
or local
dotnet new install .\aspnet-restapi-template\src\ --force
You need to clone repository or have a source code
- Create new from template:
- terminal
dotnet new morasiuapi --name MyNewApi
A clean, optioned ASP.Net REST API template.
Template is using ASP.Net 8
Features:
- CQRS with MediatR
- Clean project structure
- Swagger configuration
- Health checks
- API Versioning
- Ready to go unit tests
- Integration tests with real database in docker and
WebApplicationFactory
- Dependencies in docker (i.e. database)
- Configured Dockerfile
- IoC scope services validation
You can find more docs in specific README files.
- PostgreSQL and SQL Server switch
- Feature flags
- Install
Docker
- for
Windows
- InstallDockerDesktop
- for
- Open terminal
- Go to your
.sln
directory (directory withdocker-compose.yaml
file) - Run
docker-compose
docker compose up -d
- Run your application using your favorite IDE or terminal
cd YourName.Api && dotnet run
- Go to
http://localhost:5024/swagger/index.html
- Check if it looks good
No request will work because the migration is not created and applied. This is intentional in order not to pollute the project and the database.
- Go to
ProductController
and see how the flow looks. - Go to
Application/Requests/Products/Commands/UpdateProductCommandHandler.cs
and see how update is performed and how to communicate using exceptions. - Go to
Peristence
and see how context is configured with seeProductEntity
andProductEntityConfiguration
- Go to
Application/Services/Email
and later go toInfrastructure/Services/Email
and see how ports and adapter pattern is implemented here. - Go to
Tests/UnitTests
to check how handlers can be tests - Go to
Tests/Intergration
to see how API can be tested in almost live environment
Remove all unnecessary files and start coding :)
Created by Morasiu (morasiu2@gmail.com). Feel free to ask me any questions about it.