Starter Web API template using .NET 10 with example controllers, services, mapping and middleware. It provides a foundation for building Web APIs with JWT authentication, global exception handling, and Swagger.
Status: template ready for customization.
Forked from https://github.com/agustinafassina/TemplateApi.Net8
- 🧰 .NET 10 SDK
- 🐳 (Optional) Docker
- Template.Api: entry point, controllers, configs (Swagger, Mapperly), middleware, validators, request contracts.
- Template.Services: application services and interfaces; registered via
AddApplicationServices(). - Template.Repository: data access (repositories); registered via
AddRepositories(). - Template.Models: DTOs and shared models.
- Template.Unittests: xUnit unit tests for
Template.Services(project file:TemplateApi.Tests.csproj).
Repositories and services are registered with extension methods so Program.cs stays clean:
builder.Services.AddRepositories();— registers all repository interfaces/implementations.builder.Services.AddApplicationServices();— registers all application services (depends on repositories).
Lifetimes: repositories use Singleton for in-memory store; when you switch to Entity Framework, use Scoped for DbContext and repository implementations.
- Restore and build:
dotnet build
- Run the API:
dotnet run --project Template.Api
By default, when running in Development, Swagger should be available at http://localhost:{port}/swagger.
From the repository root (same folder as TemplateApi.sln):
dotnet test
Run only the test project:
dotnet test Template.Unittests/TemplateApi.Tests.csproj
Optional: verbose output or filter by display name:
dotnet test --verbosity normal
dotnet test --filter "FullyQualifiedName~ItemServiceTests"
The API uses FluentValidation for request DTOs (e.g. ItemCreateDto). Validators live in Template.Api/Validators/ and are registered in DI; controllers inject IValidator<T> and validate before calling services.
The template includes support for JWT authentication. Configure the values in appsettings.json or via environment variables. Example JSON configuration:
"Auth0App1": {
"Issuer": "https://your-domain.auth0.com/",
"Audience": "Your-Audience"
},
"Auth0App2": {
"Issuer": "https://another-issuer/",
"Audience": "Another-Audience"
}
And in controllers you can use:
[Authorize(AuthenticationSchemes = "Auth0App1")]
[Authorize(AuthenticationSchemes = "Auth0App2")]
- Use
appsettings.jsonandappsettings.Development.jsonfor environment-specific values. - Environment variables prefixed with
ASPNETCORE_affect host behavior.
This template exposes a simple version endpoint in ItemController.
- Request:
GET /api/v1/item/version
- curl example:
curl -i http://localhost:5000/api/v1/item/version- Response 200 (example):
"v.1.0.0"Shared formatting and AI conventions so humans, the IDE, CI and Cursor stay aligned.
.editorconfig defines charset, line endings, indentation and C# style/naming (e.g. private fields with _). Editors that support EditorConfig and dotnet format (used in CI on PRs) follow these rules.
This template ships with Cursor rules so the AI follows the project conventions and C# best practices.
- Active rules live in
.cursor/rules/:csharp.mdc(C# standards, applies to**/*.cs) andproject-conventions.mdc(repo conventions, always applied). - A copy is kept under
templates/cursor-rules/so anyone forking this template can restore them: copy the files into.cursor/rules/. - When you change a rule, update both folders so the backup stays in sync.
Build the image and run the container:
docker build -f Dockerfile -t templateapi:latest .
docker run -d -p 8787:80 -e "ASPNETCORE_ENVIRONMENT=Development" --name templateapi templateapi:latest
# Swagger: http://localhost:8787/swagger/index.html
- Fork the repo
- Create a branch (
feature/name) - Open a Pull Request describing your changes
This repository is a template created by Agustina Fassina.