how to inject and use Automapper in Umbraco applications
Hi,
I want to use Automapper to map Class objects (DTO to ViewModel and ViewModel to DTO). May I know how we inject automapper so that we don't have to do manual mappings ?
public class EmployeeListViewModel
{
public int Id { get; set; }
public string Name { get; set; }
}
public class EmployeeListDto
{
public int Id { get; set; }
public string Name { get; set; }
public EmployeeWorkLocationDto EmployeeWorkLocationDto { get; set; }
}
using AutoMapper;
public class EmployeeController : SurfaceController
{
private readonly IMapper _mapper;
public EmployeeController(IEmployeeUmbracoService EmployeeUmbracoService, IMapper mapper)
{
_EmployeeUmbracoService = EmployeeUmbracoService;
_mapper = mapper;
}
}
When I try to use automapper and inject in the constructor, I get below error:
public static class AutoMapperConfig
{
public static void RegisterMappings()
{
AutoMapper.Mapper.Configuration.AllowNullCollections = true;
// Create a reference between table and ViewModel
AutoMapper.Mapper.CreateMap<EmployeeListDto, EmployeeListViewModel>()
.ForMember(dest => dest.Id, map => map.MapFrom(src => src.Name))
.ForMember(dest => dest.Body, map => map.MapFrom(src => src.Name))
}
}
using AutoMapper;
public class EmployeeController : SurfaceController
{
// Now you can convert EmployeeListDto results to EmployeeListViewModel using single call.
public EmployeeListViewModel EmployeeResults(EmployeeListDto list)
{
var result = Mapper.Map
Do you guys know if Automapper 9 is compatible with Umbraco8 atm? was trying to use the new Automapper 9 on a new umbraco project to test a use case but i can't resolver IMapper and according Automapper documentation the static object is not available anymore.
http://docs.automapper.org/en/stable/Configuration.html
how to inject and use Automapper in Umbraco applications
Hi,
I want to use Automapper to map Class objects (DTO to ViewModel and ViewModel to DTO). May I know how we inject automapper so that we don't have to do manual mappings ?
When I try to use automapper and inject in the constructor, I get below error:
You need to first register automapping in ApplicationStarted
... }
using AutoMapper; public class EmployeeController : SurfaceController { // Now you can convert EmployeeListDto results to EmployeeListViewModel using single call. public EmployeeListViewModel EmployeeResults(EmployeeListDto list) { var result = Mapper.Map
Do you guys know if Automapper 9 is compatible with Umbraco8 atm? was trying to use the new Automapper 9 on a new umbraco project to test a use case but i can't resolver IMapper and according Automapper documentation the static object is not available anymore. http://docs.automapper.org/en/stable/Configuration.html
is working on a reply...