diff --git a/.claude/commands/DotnetVersion.md b/.claude/commands/DotnetVersion.md new file mode 100644 index 0000000..9ef04bb --- /dev/null +++ b/.claude/commands/DotnetVersion.md @@ -0,0 +1,23 @@ +You are a specialist in .NET projects. + +Scan the entire repository and locate all `.csproj` files. + +For each file: +1. Find the `` or `` element. +2. Extract the .NET version(s) defined inside it. + +Then return a structured JSON output in this format: + +{ + "projects": [ + { + "project_file": "path/to/project.csproj", + "language_version": "netX.X" + } + ] +} + +Rules: +- If `` contains multiple values (e.g., `net6.0;net8.0`), return them as an array. +- If no target framework is found, set `"language_version"` to `"unknown"`. +- Do not include any explanation or extra text — return ONLY valid JSON. \ No newline at end of file diff --git a/.claude/commands/MPlan.md b/.claude/commands/MPlan.md new file mode 100644 index 0000000..772f614 --- /dev/null +++ b/.claude/commands/MPlan.md @@ -0,0 +1,54 @@ +You are a senior .NET engineer specialized in framework version upgrades. + +Perform a full scan of this repository and identify all .NET-related projects and components. + +Your goal is to plan a **strict framework version migration to .NET 9 only**. +Do NOT propose architectural changes, performance improvements, new features, or code refactoring unless strictly required for compatibility with .NET 9. + +Analyze: +- All `.csproj` files and their current target frameworks. +- NuGet package versions and compatibility with .NET 9. +- SDK and runtime dependencies. +- CI/CD configurations and build scripts. +- Docker and deployment configurations. + +Then generate a file named `MigrationPlan.md` at the repository root with the following structure: + +## 1. Current State +- List of all projects and their current `` or ``. +- Current .NET SDK references and usage. + +## 2. Migration Scope +- Explicitly state that this is **a version-only migration**. +- List what is **in scope** and what is **out of scope**. + +## 3. Required Changes +Only include changes required to make the solution compile and run on .NET 9: +- TargetFramework updates. +- NuGet package updates (only if incompatible). +- SDK version updates (global.json, pipelines, Docker). +- Build and publish changes. + +## 4. Migration Steps +Provide a clear step-by-step incremental plan: +1. Update target frameworks. +2. Update SDK/runtime references. +3. Fix breaking changes strictly required for compilation/runtime. +4. Update pipelines and containers. +5. Run and validate tests. + +## 5. Risks & Compatibility Notes +- Known breaking changes from previous .NET versions to .NET 9. +- Potential risks of blocking dependencies. + +## 6. Validation +- Build validation steps. +- Basic runtime validation. +- Rollback strategy. + +Constraints: +- Do NOT suggest feature improvements. +- Do NOT modify architecture or structure. +- Keep suggestions minimal and strictly necessary. +- All decisions must be based only on project analysis. +- Output ONLY the `MigrationPlan.md` file. diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3a21358..bc0b86e 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,6 +12,6 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v2 with: - dotnet-version: '6.0.x' + dotnet-version: '9.0.x' - name: Build with dotnet run: dotnet build --configuration Release diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..aa58cb2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,115 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +This is an ASP.NET Core 6.0 Web API sample demonstrating RESTful API design with HATEOAS (Hypermedia as the Engine of Application State), API versioning, and Swagger documentation. The API manages a simple Food items resource with full CRUD operations. + +## Build and Run Commands + +### Build +```bash +dotnet build --configuration Release +``` + +### Run (Development) +```bash +dotnet run --project SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj +``` + +The API runs on `http://localhost:29435` by default. + +### Access Swagger UI +Navigate to `http://localhost:29435/swagger` when running in Development mode. + +## Architecture + +### Project Structure +- **Controllers/**: API endpoints organized by version (v1/, v2/) +- **Repositories/**: Data access layer with `IFoodRepository` interface and `FoodSqlRepository` implementation +- **Services/**: Business logic services (e.g., `ISeedDataService` for test data) +- **Entities/**: Database entities (e.g., `FoodEntity`) +- **Dtos/**: Data Transfer Objects (`FoodDto`, `FoodCreateDto`, `FoodUpdateDto`) +- **Models/**: Domain models (e.g., `QueryParameters`, `LinkDto`) +- **MappingProfiles/**: AutoMapper configuration (e.g., `FoodMappings`) +- **Helpers/**: Extension methods for cross-cutting concerns + +### Key Architectural Patterns + +**Dependency Injection**: Services are registered in `Program.cs`: +- `IFoodRepository` → `FoodSqlRepository` (Scoped) +- `ISeedDataService` → `SeedDataService` (Singleton) +- AutoMapper with `FoodMappings` profile + +**Repository Pattern**: Data access is abstracted through `IFoodRepository` interface. The implementation uses Entity Framework Core with an in-memory database (`UseInMemoryDatabase("FoodDatabase")`). + +**API Versioning**: Configured via `VersioningExtension.AddVersioning()`: +- URL segment versioning: `/api/v1/foods`, `/api/v2/foods` +- Header versioning: `x-api-version` header +- Media type versioning: `x-api-version` in Accept/Content-Type +- Default version: 1.0 +- Controllers use `[ApiVersion("1.0")]` or `[ApiVersion("2.0")]` attributes +- Routes use `[Route("api/v{version:apiVersion}/[controller]")]` + +**HATEOAS Implementation**: +- v1 FoodsController includes hypermedia links in responses +- `ExpandSingleFoodItem()` adds `links` array to each resource +- `CreateLinksForCollection()` provides navigation links (self, first, last, next, previous) +- Links use named routes (e.g., `nameof(GetSingleFood)`) +- The `LinkDto` model represents hypermedia links +- `DynamicExtensions.ToDynamic()` converts DTOs to expandable objects for adding links + +**Pagination**: Handled via `QueryParameters` model: +- `Page`: Current page number (default: 1) +- `PageCount`: Items per page (max: 50, default: 50) +- `OrderBy`: Sort field (default: "Name") +- Pagination metadata returned in `X-Pagination` response header +- Dynamic sorting via `System.Linq.Dynamic.Core` library + +**Filtering**: QueryParameters supports text search via `Query` property. The repository searches both `Name` and `Calories` fields. + +**AutoMapper**: Maps between Entities and DTOs: +- `FoodEntity` ↔ `FoodDto` / `FoodCreateDto` / `FoodUpdateDto` +- Configuration in `MappingProfiles/FoodMappings.cs` + +**JSON Patch**: PATCH endpoint (`PartiallyUpdateFood`) uses `JsonPatchDocument` from `Microsoft.AspNetCore.JsonPatch` for partial updates. + +**CORS**: Configured via `CorsExtension.AddCustomCors("AllowAllOrigins")` - allows all origins in this sample. + +**Seed Data**: In Development mode, `SeedDataExtension.SeedData()` populates the in-memory database with test food items. + +### Response Patterns + +**v1 API responses** include: +- `value`: Array of resources or single resource with embedded HATEOAS links +- `links`: Array of `LinkDto` objects for navigation + +**Pagination metadata** (in `X-Pagination` header): +```json +{ + "totalCount": 20, + "pageSize": 10, + "currentPage": 1, + "totalPages": 2 +} +``` + +## Key Dependencies + +- **Microsoft.EntityFrameworkCore.InMemory**: In-memory database provider +- **AutoMapper**: Object-to-object mapping +- **Microsoft.AspNetCore.Mvc.Versioning**: API versioning +- **Swashbuckle.AspNetCore**: Swagger/OpenAPI generation +- **Microsoft.AspNetCore.Mvc.NewtonsoftJson**: JSON PATCH support +- **System.Linq.Dynamic.Core**: Dynamic LINQ for runtime query construction + +## Development Notes + +**Configuration**: Settings in `appsettings.json` and `appsettings.Development.json`. + +**Exception Handling**: Production mode uses `ExceptionExtension.AddProductionExceptionHandling()` for centralized error handling. + +**Swagger Configuration**: `ConfigureSwaggerOptions` class implements `IConfigureOptions` to configure Swagger per API version. + +**Routing**: Lowercase URLs enforced via `AddRouting(options => options.LowercaseUrls = true)`. diff --git a/MigrationPlan.md b/MigrationPlan.md new file mode 100644 index 0000000..947963a --- /dev/null +++ b/MigrationPlan.md @@ -0,0 +1,421 @@ +# .NET 9 Migration Plan + +## 1. Current State + +### Projects and Target Frameworks +- **SampleWebApiAspNetCore.csproj**: `net6.0` + - Location: `/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj` + - Type: ASP.NET Core Web API + +### Current Dependencies +- **AutoMapper**: 11.0.1 +- **AutoMapper.Extensions.Microsoft.DependencyInjection**: 11.0.0 +- **Microsoft.AspNetCore.Mvc.NewtonsoftJson**: 6.0.8 +- **Microsoft.AspNetCore.Mvc.Versioning**: 5.0.0 (deprecated) +- **Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer**: 5.0.0 (deprecated) +- **Microsoft.EntityFrameworkCore.InMemory**: 6.0.8 +- **Swashbuckle.AspNetCore**: 6.4.0 +- **System.Linq.Dynamic.Core**: 1.2.19 + +### SDK and Runtime +- **GitHub Actions Workflow**: .NET SDK 6.0.x + - File: `.github/workflows/dotnetcore.yml:15` + - Action: `actions/setup-dotnet@v2` + +### Build Configuration +- No `global.json` file present +- No Docker configuration found +- Build command: `dotnet build --configuration Release` + +## 2. Migration Scope + +### In Scope +This migration is **strictly a framework version upgrade to .NET 9**. The following changes are included: + +- Update `TargetFramework` from `net6.0` to `net9.0` +- Update NuGet packages to .NET 9-compatible versions +- Replace deprecated API versioning packages with modern equivalents +- Update GitHub Actions workflow to use .NET 9 SDK +- Address breaking changes required for compilation and runtime compatibility +- Validate build and basic functionality + +### Out of Scope +The following are **explicitly excluded** from this migration: + +- Code refactoring or architectural changes +- Performance optimizations +- New feature additions +- Code style or formatting changes +- Migration to Minimal APIs +- Migration from Newtonsoft.Json to System.Text.Json +- Documentation updates (beyond this plan) +- Test coverage improvements +- Security enhancements (beyond what .NET 9 provides) + +## 3. Required Changes + +### 3.1 Project File Updates + +**SampleWebApiAspNetCore.csproj**: + +1. **Target Framework** (Line 4): + - Change: `net6.0` → `net9.0` + +2. **Package Updates**: + - **AutoMapper**: 11.0.1 → 13.0.1 (latest stable before license requirement in v14+) + - **AutoMapper.Extensions.Microsoft.DependencyInjection**: Remove package (deprecated, no longer needed) + - **Microsoft.AspNetCore.Mvc.NewtonsoftJson**: 6.0.8 → 9.0.0 + - **Microsoft.AspNetCore.Mvc.Versioning**: 5.0.0 → Replace with **Asp.Versioning.Mvc** 8.1.0 + - **Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer**: 5.0.0 → Replace with **Asp.Versioning.Mvc.ApiExplorer** 8.1.0 + - **Microsoft.EntityFrameworkCore.InMemory**: 6.0.8 → 9.0.0 + - **Swashbuckle.AspNetCore**: 6.4.0 → 7.2.0 (or latest 7.x compatible with .NET 9) + - **System.Linq.Dynamic.Core**: 1.2.19 → 1.4.10 (latest stable) + +### 3.2 Code Changes + +**Program.cs** - API Versioning namespace changes: + +The deprecated `Microsoft.AspNetCore.Mvc.Versioning` packages use different namespaces than the new `Asp.Versioning.Mvc` packages. Expected changes: + +1. Update using statements: + - Old: `using Microsoft.AspNetCore.Mvc.Versioning;` + - New: `using Asp.Versioning;` + +2. Service registration may require slight syntax adjustments (verify after package update) + +**Note**: The exact code changes will be confirmed after attempting compilation with updated packages. The `Asp.Versioning` packages maintain similar API surface area to minimize code changes. + +### 3.3 CI/CD Updates + +**.github/workflows/dotnetcore.yml** (Line 15): + +```yaml +# Current +dotnet-version: '6.0.x' + +# Updated +dotnet-version: '9.0.x' +``` + +### 3.4 SDK Version + +**Recommendation**: Add `global.json` to pin SDK version for consistency: + +```json +{ + "sdk": { + "version": "9.0.100", + "rollForward": "latestFeature" + } +} +``` + +## 4. Migration Steps + +Execute the migration in the following order: + +### Step 1: Prepare and Backup +1. Ensure current code compiles on .NET 6: `dotnet build --configuration Release` +2. Commit all pending changes to source control +3. Create migration branch: `git checkout -b migrate-to-dotnet9` + +### Step 2: Update SDK References +1. Add `global.json` with .NET 9 SDK version (optional but recommended) +2. Update `.github/workflows/dotnetcore.yml` to use .NET 9 SDK + +### Step 3: Update Project Target Framework +1. Edit `SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj` +2. Change `net6.0` to `net9.0` + +### Step 4: Update NuGet Packages +1. Remove deprecated package: + ```bash + dotnet remove SampleWebApiAspNetCore package AutoMapper.Extensions.Microsoft.DependencyInjection + ``` + +2. Replace versioning packages: + ```bash + dotnet remove SampleWebApiAspNetCore package Microsoft.AspNetCore.Mvc.Versioning + dotnet remove SampleWebApiAspNetCore package Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer + dotnet add SampleWebApiAspNetCore package Asp.Versioning.Mvc --version 8.1.0 + dotnet add SampleWebApiAspNetCore package Asp.Versioning.Mvc.ApiExplorer --version 8.1.0 + ``` + +3. Update remaining packages: + ```bash + dotnet add SampleWebApiAspNetCore package AutoMapper --version 13.0.1 + dotnet add SampleWebApiAspNetCore package Microsoft.AspNetCore.Mvc.NewtonsoftJson --version 9.0.0 + dotnet add SampleWebApiAspNetCore package Microsoft.EntityFrameworkCore.InMemory --version 9.0.0 + dotnet add SampleWebApiAspNetCore package Swashbuckle.AspNetCore --version 7.2.0 + dotnet add SampleWebApiAspNetCore package System.Linq.Dynamic.Core --version 1.4.10 + ``` + +### Step 5: Fix Breaking Changes +1. Update namespace imports in code files (Program.cs, Controllers, Extensions): + - Replace `Microsoft.AspNetCore.Mvc.Versioning` with `Asp.Versioning` + - Replace `Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer` with `Asp.Versioning.ApiExplorer` + +2. Review AutoMapper registration in `Program.cs`: + - Since `AutoMapper.Extensions.Microsoft.DependencyInjection` is removed, verify that AutoMapper 13.x includes DI support natively + - Expected: `builder.Services.AddAutoMapper(typeof(FoodMappings));` should continue to work + +3. Attempt build: `dotnet build --configuration Release` + +4. Address any compilation errors: + - Review compiler messages + - Consult .NET 9 breaking changes documentation for specific issues + - Make minimal code changes required for compilation + +### Step 6: Runtime Validation +1. Clean and rebuild: + ```bash + dotnet clean + dotnet build --configuration Release + ``` + +2. Run the application: + ```bash + dotnet run --project SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj + ``` + +3. Basic smoke tests: + - Verify Swagger UI loads: `http://localhost:29435/swagger` + - Test GET all foods: `http://localhost:29435/api/v1/foods` + - Test GET single food: `http://localhost:29435/api/v1/foods/1` + - Verify API versioning works for v1 and v2 endpoints + - Test HATEOAS links in responses + +### Step 7: CI/CD Validation +1. Commit changes: `git commit -m "Migrate to .NET 9"` +2. Push to trigger GitHub Actions workflow +3. Verify workflow completes successfully + +### Step 8: Finalize +1. Review all changes +2. Merge migration branch to main (or create PR) +3. Tag release: `git tag v9.0-migration` + +## 5. Risks & Compatibility Notes + +### Known Breaking Changes (.NET 6 → .NET 9) + +**High Impact**: +- **BinaryFormatter removal**: Not used in this project (low risk) +- **API Versioning package replacement**: Requires namespace updates and potential API changes (medium risk) +- **AutoMapper DI extension removal**: AutoMapper 13+ includes DI support natively, but registration syntax may differ (medium risk) + +**Medium Impact**: +- **EF Core 9 changes**: Pending migrations throw at runtime; this project uses in-memory database with seed data (low risk for this project) +- **ASP.NET Core middleware changes**: MapStaticAssets and proxy headers changes unlikely to affect this API-only project (low risk) +- **JSON serialization**: Continuing to use Newtonsoft.Json, so minimal impact (low risk) + +**Low Impact**: +- **Trimming/AOT**: Not applicable as this project doesn't use ahead-of-time compilation +- **Reflection changes**: AutoMapper uses reflection; version 13.x is compatible with .NET 9 + +### Potential Blocking Issues + +1. **Third-party package compatibility**: + - **Risk**: `System.Linq.Dynamic.Core` or `Swashbuckle.AspNetCore` may have .NET 9 compatibility issues + - **Mitigation**: Versions selected are confirmed compatible; fallback to earlier versions if needed + +2. **API Versioning migration**: + - **Risk**: `Asp.Versioning.Mvc` API may differ from `Microsoft.AspNetCore.Mvc.Versioning` + - **Mitigation**: Both packages maintain similar API surface; consult migration guide if issues arise + +3. **AutoMapper breaking changes**: + - **Risk**: AutoMapper 13.x may have breaking API changes from 11.x + - **Mitigation**: Review AutoMapper 12.x and 13.x release notes; minimal changes expected for this simple mapping configuration + +4. **Swashbuckle .NET 9 support**: + - **Risk**: Microsoft removed Swashbuckle from default .NET 9 templates + - **Mitigation**: Swashbuckle remains compatible as a community package; manually include in project + +### Dependency Risks + +- **No global.json**: Without SDK pinning, different developer machines may use different .NET 9 patch versions + - **Mitigation**: Add `global.json` to ensure consistency + +- **GitHub Actions**: Using `actions/setup-dotnet@v2` may be outdated + - **Current**: Consider updating to `@v4` for better .NET 9 support + - **Out of scope**: Stick with v2 unless it fails to install .NET 9 + +## 6. Validation + +### Build Validation + +**Pre-migration baseline**: +```bash +git checkout main +dotnet build --configuration Release +# Expected: Build succeeded +``` + +**Post-migration validation**: +```bash +git checkout migrate-to-dotnet9 +dotnet clean +dotnet build --configuration Release +# Expected: Build succeeded with 0 errors, 0 warnings +``` + +**Package restore verification**: +```bash +dotnet restore +# Expected: All packages restore successfully for net9.0 +``` + +### Runtime Validation + +**Application startup**: +```bash +dotnet run --project SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj +# Expected: Application starts on http://localhost:29435 +# Expected: No runtime exceptions in console output +``` + +**Swagger UI validation**: +- Navigate to `http://localhost:29435/swagger` +- Expected: Swagger UI loads successfully +- Expected: Both v1 and v2 API versions appear in version selector + +**API endpoint validation**: + +1. **GET /api/v1/foods** (HATEOAS with pagination): + ```bash + curl http://localhost:29435/api/v1/foods + ``` + - Expected: 200 OK with `value` array and `links` array + - Expected: X-Pagination header present + - Expected: HATEOAS links include self, first, last + +2. **GET /api/v1/foods/{id}**: + ```bash + curl http://localhost:29435/api/v1/foods/1 + ``` + - Expected: 200 OK with single food item + - Expected: HATEOAS links present + +3. **POST /api/v1/foods**: + ```bash + curl -X POST http://localhost:29435/api/v1/foods \ + -H "Content-Type: application/json" \ + -d '{"name":"Test Food","type":"Snack","calories":100,"created":"2025-11-21T00:00:00Z"}' + ``` + - Expected: 201 Created with Location header + +4. **PATCH /api/v1/foods/{id}** (JSON Patch): + ```bash + curl -X PATCH http://localhost:29435/api/v1/foods/1 \ + -H "Content-Type: application/json-patch+json" \ + -d '[{"op":"replace","path":"/name","value":"Updated Name"}]' + ``` + - Expected: 204 No Content or 200 OK + +5. **DELETE /api/v1/foods/{id}**: + ```bash + curl -X DELETE http://localhost:29435/api/v1/foods/1 + ``` + - Expected: 204 No Content + +6. **API v2 endpoint**: + ```bash + curl http://localhost:29435/api/v2/foods + ``` + - Expected: 200 OK (response format depends on v2 implementation) + +**AutoMapper validation**: +- Verify POST/PUT operations work correctly (validates mapping from DTOs to Entities) +- No AutoMapper configuration errors in application logs + +**EF Core validation**: +- Verify seed data loads on startup (check logs for seed operation) +- Verify CRUD operations work against in-memory database + +### CI/CD Validation + +**GitHub Actions workflow**: +1. Push migration branch to GitHub +2. Verify workflow triggers and runs +3. Check workflow logs for: + - .NET 9 SDK installation succeeds + - `dotnet build --configuration Release` succeeds + - No errors or warnings in build output + +### Performance Baseline (Optional but Recommended) + +While performance optimization is out of scope, establishing a baseline helps detect regressions: + +**Before migration** (on .NET 6): +- Note application startup time +- Note first request response time + +**After migration** (on .NET 9): +- Compare startup time (expected: similar or faster) +- Compare first request response time (expected: similar or faster) + +**Note**: .NET 9 generally provides performance improvements; significant regressions indicate an issue. + +## Rollback Strategy + +If critical issues are encountered during migration: + +### Immediate Rollback +```bash +git checkout main +dotnet build --configuration Release +dotnet run --project SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj +``` + +### Rollback After Merge +If issues are discovered after merging to main: + +1. **Revert commit**: + ```bash + git revert + git push + ``` + +2. **Restore from tag** (if tagged): + ```bash + git checkout tags/ + git checkout -b rollback-branch + ``` + +3. **CI/CD rollback**: + - GitHub Actions will automatically build reverted code + - No additional CI/CD changes needed + +### Partial Rollback +If only specific packages cause issues: + +1. Revert problematic package to .NET 6 version temporarily +2. Keep `net9.0` (most .NET 6 packages work on .NET 9) +3. Investigate and resolve compatibility issue +4. Re-apply package update once resolved + +### Data Considerations +- **No data migration required**: Project uses in-memory database with seed data +- **No schema changes**: EF Core migrations not applicable +- **No persistent state**: Rollback has zero data impact + +--- + +## Summary + +This migration plan provides a **strict framework version upgrade from .NET 6 to .NET 9** with minimal code changes. The primary changes are: + +1. Target framework update: `net6.0` → `net9.0` +2. Package updates to .NET 9-compatible versions +3. API versioning package replacement: `Microsoft.AspNetCore.Mvc.Versioning` → `Asp.Versioning.Mvc` +4. AutoMapper DI extension removal (functionality now built-in) +5. GitHub Actions workflow SDK update: `6.0.x` → `9.0.x` + +The migration is low-risk due to: +- Single project with clear dependencies +- In-memory database (no data migration) +- Well-maintained packages with .NET 9 support +- No advanced features (AOT, trimming) that increase complexity + +**Estimated effort**: 2-4 hours for migration + validation +**Recommended approach**: Execute all steps in sequence, validate thoroughly at each step diff --git a/SampleWebApiAspNetCore/ConfigureSwaggerOptions.cs b/SampleWebApiAspNetCore/ConfigureSwaggerOptions.cs index f37127c..6d0faa3 100644 --- a/SampleWebApiAspNetCore/ConfigureSwaggerOptions.cs +++ b/SampleWebApiAspNetCore/ConfigureSwaggerOptions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Asp.Versioning.ApiExplorer; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; diff --git a/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs b/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs index 5957ceb..932deab 100644 --- a/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs +++ b/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs @@ -1,4 +1,5 @@ -using AutoMapper; +using Asp.Versioning; +using AutoMapper; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using SampleWebApiAspNetCore.Dtos; diff --git a/SampleWebApiAspNetCore/Controllers/v2/FoodsController.cs b/SampleWebApiAspNetCore/Controllers/v2/FoodsController.cs index a3477c1..5c3e1cd 100644 --- a/SampleWebApiAspNetCore/Controllers/v2/FoodsController.cs +++ b/SampleWebApiAspNetCore/Controllers/v2/FoodsController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; namespace SampleWebApiAspNetCore.Controllers.v2 { diff --git a/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs b/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs index a3d80d1..8068a1c 100644 --- a/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs +++ b/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Versioning; +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; namespace SampleWebApiAspNetCore.Helpers @@ -17,8 +17,8 @@ public static void AddVersioning(this IServiceCollection services) config.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), new HeaderApiVersionReader("x-api-version"), new MediaTypeApiVersionReader("x-api-version")); - }); - services.AddVersionedApiExplorer( + }) + .AddApiExplorer( options => { options.GroupNameFormat = "'v'VVV"; diff --git a/SampleWebApiAspNetCore/Program.cs b/SampleWebApiAspNetCore/Program.cs index 985395e..ce98c26 100644 --- a/SampleWebApiAspNetCore/Program.cs +++ b/SampleWebApiAspNetCore/Program.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Asp.Versioning.ApiExplorer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Newtonsoft.Json.Serialization; diff --git a/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj b/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj index 134c68c..595a8b7 100644 --- a/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj +++ b/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj @@ -1,20 +1,19 @@  - net6.0 + net9.0 enable enable - - - - - - - - + + + + + + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..ff07225 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.203", + "rollForward": "latestFeature" + } +}