How macrocodechannel/api-versioning-in-asp.net-core-web-api works
This is a versioned ASP.NET Core student-management API. Clients select API versions 1–3, then use the corresponding Students controller for list, lookup, create, update, or delete operations; the controllers use a shared EF Core context for student data. The host configures SQL Server persistence and version-aware Swagger generation. Source excerpts establish the controller and startup wiring; migrations and runtime behavior beyond those excerpts are not expanded here.
Main entry points: Program.cs Application host · ApplicationDbContext.cs EF data context · v1/StudentsController.cs Students v1 · v2/StudentsController.cs Students v2
Components 10
Versioned API
- Students v1
StudentsManagementApi/Controllers/v1/StudentsController.cs - Students v2
StudentsManagementApi/Controllers/v2/StudentsController.cs - Students v3
StudentsManagementApi/Controllers/v3/StudentsController.cs
Student data
- EF data context
StudentsManagementApi/Database/ApplicationDbContext.cs - Student record
StudentsManagementApi/Models/Student.cs - SQL Server
API documentation
- Versioned Swagger
StudentsManagementApi/Swagger/ConfigureSwaggerOptions.cs - Swagger defaults
StudentsManagementApi/Swagger/SwaggerDefaultValues.cs
Other components
- API client
- Application host
StudentsManagementApi/Program.cs
Connections 17
- API client → Students v1: requests v1
StudentsManagementApi/Controllers/v1/StudentsController.cs - API client → Students v2: requests v2
StudentsManagementApi/Controllers/v2/StudentsController.cs - API client → Students v3: requests v3
StudentsManagementApi/Controllers/v3/StudentsController.cs - Application host → Students v1: maps controllers
StudentsManagementApi/Program.cs - Application host → Students v2: maps controllers
StudentsManagementApi/Program.cs - Application host → Students v3: maps controllers
StudentsManagementApi/Program.cs - Students v1 → EF data context: queries and saves
StudentsManagementApi/Controllers/v1/StudentsController.cs - Students v2 → EF data context: queries and saves
StudentsManagementApi/Controllers/v2/StudentsController.cs - Students v3 → EF data context: queries and saves
StudentsManagementApi/Controllers/v3/StudentsController.cs - Students v1 → Student record: accepts and returns
StudentsManagementApi/Controllers/v1/StudentsController.cs - Students v2 → Student record: accepts and returns
StudentsManagementApi/Controllers/v2/StudentsController.cs - Students v3 → Student record: accepts and returns
StudentsManagementApi/Controllers/v3/StudentsController.cs - EF data context → Student record: models set
StudentsManagementApi/Database/ApplicationDbContext.cs - Application host → EF data context: configures SQL
StudentsManagementApi/Program.cs - EF data context → SQL Server: persists data
- Application host → Versioned Swagger: registers options
StudentsManagementApi/Program.cs - Application host → Swagger defaults: registers filter
StudentsManagementApi/Program.cs