Skip to content

Replace AutoMapper with explicit FromModel() extension methods in V3 API#3327

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/replace-automapper-dto-methods
Draft

Replace AutoMapper with explicit FromModel() extension methods in V3 API#3327
Copilot wants to merge 4 commits into
mainfrom
copilot/replace-automapper-dto-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

Context

AutoMapper adds implicit magic that makes mapping logic hard to trace. Replacing it with explicit static FromModel() methods makes the data flow obvious and removes a runtime dependency on reflection-based mapping.

Changes proposed in this pull request

Removed AutoMapper infrastructure:

  • Deleted all 12 MapperProfile.cs files across V20240101–V20260416
  • Removed AutoMapper NuGet package reference
  • Removed global using AutoMapper, AddAutoMapper() service registration, and the ITypeConverter<,> Scrutor scan
  • Deleted Infrastructure/Mapping/OptionMapper.cs (generic Option/OneOf type converters no longer needed)

Added explicit mapping:

  • Static FromModel() factory methods on all V3 response records (e.g. GetPersonResponse.FromModel(result))
  • Extension methods for DTOs shared across versions: TrnRequestInfo, QtsInfo, alert types, induction info, routes-to-professional-status, etc.
  • Extension files placed in TeachingRecordSystem.Api where they reference Api-layer types, and in TeachingRecordSystem.Core where they reference only Core types

Updated all V3 controllers to drop IMapper constructor injection and call FromModel() directly:

// Before
return result.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r)));

// After
return result.ToActionResult(r => Ok(GetPersonResponse.FromModel(r)));

Guidance to review

  • Each API version has its own FromModel() implementation; look for version-specific field additions (e.g. AwardedOrApprovedCount added in V20250327's QtsInfo)
  • Where extension method ambiguity arose between versions (e.g. QtsInfo.FromModel() in V20240814 vs V20250327), the mapping is inlined directly in the response record rather than using an extension method
  • The V20250627/DtoExtensions.cs in the Api project handles the richer route-to-professional-status mapping that references both Postgres model types and Implementation DTOs

Checklist

  • Attach to Trello card
  • Rebased master
  • Cleaned commit history
  • Tested by running locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants