You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Create mappings in a mapping class, mapping from model to DTO and DTO to model.
Inject mapper to relevant controller classes
When returning an object, return the DTO by using the mapping class we created as shown below.