I have used Automapper in one of my project before, now I want to use ValueInjecter for the other one.
These are ViewModels
public class ApplicantListViewModel : BaseViewModel
{
public int Id {get; set;}
public string Name {get;set;}
public string CourseName {get;set;}
}
public class CourseListViewModel : BaseViewModel
{
public int Id {get; set;}
public string Name {get;set;}
public int Applicants {get;set;}
}
These are my DTOs
public class Course : BaseEntity
{
public string Name { get; set; }
public virtual IList<Applicant> Applicants { get; set; }
}
public class Applicant : BaseEntity
{
public string Name { get; set; }
public int CourseId { get; set; }
public virtual Course Course { get; set; }
}
I can map DTOs to ViewModels sth like below with Automapper
AutoMapper.Mapper.CreateMap<Applicant, ApplicantListViewModel>();
AutoMapper.Mapper.CreateMap<Course, CourseListViewModel>()
.ForMember(s => s.Applicants, d => d.MapFrom(s => s.Applicants.Count));
Then it is automatically map Course to CourseListViewModel and Applicant to ApplicantListViewModel. When it maps I can see that ApplicantListViewModel's CourseName' property gets its value from Course.Name without any special configuration by using AutoMapper but ValueInjector doesnt map(CourseName become null) it. Also CourseListViewModel's Applicants property gets its value from Applicants.Count with little configuration.
How to do these mappings by ValueInjecter easier ?