Phase 2: Create .NET Core 6.0 Web API with Read-Only Endpoints #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phase 2: Add .NET Core 6.0 Web API with Read-Only Endpoints
Summary
This PR implements Phase 2 of the .NET Framework to .NET Core migration by creating a new .NET Core 6.0 Web API project that runs alongside the existing .NET Framework MVC application, sharing the same SQL Server database.
Three new projects are added:
SampleWebApp.Core - Class library containing entities, DTOs, and MediatR handlers for read-only queries. Handlers use AutoMapper to map entities to DTOs and include related data via EF Core's
.Include().SampleWebApp.Api - Web API project with three controllers exposing read-only endpoints:
GET /api/blogsandGET /api/blogs/{id}GET /api/tagsandGET /api/tags/{id}GET /api/posts?blogId={blogId}andGET /api/posts/{id}SampleWebApp.Api.Tests - Test project with 42 unit and integration tests using xUnit, FluentAssertions, and EF Core InMemory provider.
The API includes Swagger UI for testing endpoints in development mode.
Updates Since Last Revision
Added comprehensive test suite (
SampleWebApp.Api.Tests):Review & Testing Checklist for Human
SampleWebApp.Core/Entities/against the existingDataLayer/DataClasses/Concrete/to ensure all properties and constraints match.Server=(localdb)\\mssqllocaldb). Update for your environment if needed.Recommended test plan:
dotnet test SampleWebApp.Api.Teststo verify all 42 tests passdotnet run --project SampleWebApp.Api/swaggerand test each endpointNotes
The handlers inject
DbContext(abstract base class) rather than the concreteSampleWebAppDbContext. This is registered in DI viaAddScoped<DbContext>(provider => provider.GetRequiredService<SampleWebAppDbContext>()).The test project uses EF Core InMemory provider which does not enforce referential integrity the same way SQL Server does. Integration tests verify API behavior but do not guarantee database compatibility.
Link to Devin run: https://app.devin.ai/sessions/d522c71ef39e4168b74915566b62b279
Requested by: Abhay Aggarwal (@abhay-codeium)