I have a web solution which includes a web UI, web api layer, service objects, and a data layer which encapsulates repositories (sometimes using a Unit of Work pattern) and Entity Framework entities. My web service is returning JSON which I'm deserializing within the UI controller like this:
var response = await httpClient.GetAsync(endpoint);
var result = JsonConvert.DeserializeObject<anyTypeHere>(await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync());
My web api layer calls various "services" (all represented as their own library project - ie: Accounting Service, EnrollmentService, CalendarService). Within each service object is code to access data entities thru Repositories:
// returns entity object
var customer = UnitOfWork.PatientRepository.GetCustomerById();
I'd like to use a tool like AutoMapper to map entity objects to dto/domain objects thus returning the dto objects back to the UI caller.
My question are:
Where should I add Automapper reference and mapping code? (ie: WebApi, service project, repository layer, etc...)
Should I create a separate library that contains the DTO objects and reference this in my UI client as well as api and service layer(s)?