Starter template with vertical-slice Minimal API, JWT auth, EF Core + SQL Server, Serilog, FluentValidation, ProblemDetails, health checks, Swagger (Dev), and Testcontainers-based integration tests—ready for local or Docker workflows.
- Minimal API slices (
Features/Auth/Login,Features/Users/Create) - JWT bearer auth with Admin/User roles; AdminOnly policy
- EF Core + SQL Server migrations; Serilog request logging; global ProblemDetails; health checks; Swagger in Development
- Unit and integration tests (Testcontainers SQL Server)
- Prereqs: .NET 8 SDK; SQL reachable (adjust
ConnectionStrings:Defaultinsrc/ServiceStarter.Api/appsettings.jsonif needed). - Run:
dotnet restore && dotnet run --project src/ServiceStarter.Api - URLs: API
http://localhost:5171, Swaggerhttp://localhost:5171/swagger, pingGET /ping, healthGET /health/liveand/health/ready.
docker compose up --build- URLs: API
http://localhost:8080, Swaggerhttp://localhost:8080/swagger(Dev), DBlocalhost:1433(passwordYour_password123). Uses the bundled SQL container.
POST /auth/loginwith{"email":"someone@admin.local","password":"password123"}→{ "accessToken": "..." }.- Any
@admin.localemail gets Admin role; other domains get User role.
- Development / Testing: migrations apply automatically on startup.
- Production: opt-in by setting
Database:ApplyMigrationsOnStartup=true(or equivalent env var); default is off.
- Folder:
src/ServiceStarter.Api/Features/<Area>/<Action>/. - Include:
<Action>Request,<Action>RequestValidator,<Action>Response,<Action>Endpoints(route mapping), plus handlers/services as needed. - Use
ValidationFilter<T>on endpoints, return ProblemDetails for errors, add migrations when data changes, and cover with unit + integration tests.
- Unit:
dotnet test tests/ServiceStarter.UnitTests - Integration (Docker daemon required):
dotnet test tests/ServiceStarter.IntegrationTests(WebApplicationFactory + Testcontainers SQL Servermcr.microsoft.com/mssql/server:2022-latest). - Full suite:
dotnet test -c Release
- Rename solution/project folders and
*.csprojfiles; update project references. - Replace namespaces from
ServiceStarterto your name (src + tests). - Update docker image/tag names and compose references; adjust connection strings and JWT settings.
- Verify with
dotnet test -c Release.
src/ServiceStarter.Api— app, slices, infrastructure, migrations.tests/ServiceStarter.UnitTests— validators and small units.tests/ServiceStarter.IntegrationTests— WebApplicationFactory + Testcontainers (auth, users, health, swagger, problem details).docker/— Dockerfile,docker-compose.yml;docs/— reference material.
This project is licensed under the MIT License – see the LICENSE file for details.