Skip to content
Wendy Yao edited this page Mar 15, 2020 · 3 revisions

A mapper was needed to prevent cyclic references when having certain API calls (getAll).
AutoMapper was chosen as it is one of the most popular mapping applications in C#, and saves time when mapping to dissimilar types.

Benefits:

  • Reduces duplicate code
  • Saves time writing boilerplate mapping classes
  • Easy to use

Implementation:

  • Add AutoMapper reference in StartUp.cs

image

  • Create mappings in a mapping class, mapping from model to DTO and DTO to model.

image

  • Inject mapper to relevant controller classes

image

  • When returning an object, return the DTO by using the mapping class we created as shown below.

image

Clone this wiki locally