Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm currently trying to use custom AutoMapper profiles in v8. I'm registering the profile in a custom IUserComposer with composition.Register<Profile, CalendarToCalendarProfile>(Lifetime.Transient);.
My profile looks currently like this:
public class CalendarToCalendarProfile : Profile
var map = CreateMap<CalendarDto, Models.Calendar>(MemberList.Destination);
public override string ProfileName => "CalendarDtoToCalendar";
When I now try to map my classes it can't find a registered mapper.
I tried using Mapper.Map() and injecting IMapper to my class.
I have been setting up the profiles as part of the Composer .
so with for example in the Compose function of an IComposer class :
with a profile class like :
internal class MyCustomProfile : Profile
// dto -> model
// model -> dto
this seems to be working for me.
the only other thing to consider is order - I set up the profile mappings first in the Composer so that they are then available in all the services/classes that might be setup later in the function
how do you actually do the mapping? Do you try to get them via DI or just calling the static Mapper.Map() method?
calling the static Mapper.Map often in a repository.
.Select(x => Mapper.Map<TranslationJob>(x));
Ok after a bit of debugging I found out that the problem is not actually caused by automapper but by IQuery that I try to use. As these are also using mappers which you can't implement yourself as they need an attribute which is internal. And tbh I'm not sure why it is needed.
The way Automapper 9 works with Umbraco 8.6.1 for me.
You need something like this in Composer for DI.
However i am not sure if i have to use factory somehow.
public class Composer : IUserComposer
public void Compose(Composition composition)
public IMapper GetMapper(IFactory factory)
var config = new MapperConfiguration(cfg =>
var profiles = GetType().Assembly.GetTypes().Where(x => typeof(Profile).IsAssignableFrom(x));
foreach (var profile in profiles)
cfg.AddProfile(Activator.CreateInstance(profile) as Profile);
return new Mapper(config);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted