What about isolating your mapping in its own class.
public class UserProfile: Profile
{
public UserProfile()
{
CreateMap<User, UserDto>(MemberList.None);
}
}
Your Profiles registration may differ, but here is how they could be dynamically registered.
public class MapperProvider
{
private readonly Container container;
public MapperProvider(Container container)
{
this.container = container;
}
public IMapper GetMapper()
{
var mce = new MapperConfigurationExpression();
mce.ConstructServicesUsing(container.GetInstance);
MapperConfiguration mc = GetMapperConfiguration(mce);
IMapper m = new Mapper(mc, t => container.GetInstance(t));
return m;
}
public static MapperConfiguration GetMapperConfiguration(MapperConfigurationExpression mce)
{
var profiles = typeof(ApplicationProfile).Assembly.GetTypes()
.Where(t => typeof(Profile).IsAssignableFrom(t))
.ToList();
mce.AddProfiles(profiles);
var mc = new MapperConfiguration(mce);
mc.AssertConfigurationIsValid();
return mc;
}
}
That way, you can search for that profile class by its name, and easily navigate to your mapping.
It will work if you know that User mappings are in the UserProfile
class.