We are configuring automapper for my asp.net MVC/Web API project in the method definition as follows.
public HttpResponseMessage GetDetails(int assignmentId)
{
var valuation = _valuationRepository.GetOneById(assignmentId);
Mapper.CreateMap<UserLicenses, UserLicenseResponseModel>()
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.States.StateCode))
.ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.UserId))
.ForMember(dest => dest.FullName, opt => opt.MapFrom(src => (src.UserProfile != null) ? (src.UserProfile.FirstName + ' ' + src.UserProfile.LastName) : " "));
Mapper.CreateMap<AdditionalExpenses, AdditionalExpensesResponseModel>();
Mapper.CreateMap<ValuationAssignment, ValuationAssignmentResponseModel>();
var model = Mapper.Map<ValuationAssignmentResponseModel>(valuationAssignment);
return Request.CreateResponse(HttpStatusCode.OK, new { Assignment = model });
}
We are noticing that api is randomly not mapping values and response json is returning null values for the mapped fields.
When this happens I'm recycling the app pool and it seems to work for a period of time and we run into the issue again.
Documentation refers to storing all the mappings in Application_Start in Global.asax. However, we are setting them in the method definition - Is that why we are seeing this issue?