so this is my first Stack Overflow question and I hope do I good job of giving enough detail for help. I'm trying to use AutoMappper with dotnet 3.1 with dependency injection however it doesn't seem to be registering my maps the way it says it does.
The error I am receiving:
AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
User -> UserCustomerDto
In my Startup.cs I have : services.AddAutoMapper(typeof(Startup)); Inside the IServiceCollection area
I have my User model and my various DTO models created.
Here is an example Profile model that I have:
public class UserCustomerProfile : Profile
{
public UserCustomerProfile()
{
CreateMap<User, UserCustomerDto>();
CreateMap<UserCustomerDto, User>();
}
}
My DTO Models have all the fields that my User Model has minus a few, the ones I do not want to surface to the UI that is.
The documentation has been rather difficult to follow as there is examples to non-dependency injection as well as pre-9.0 where configuration was required during the startup of the project.
I also tried using .ReverseMap() on the CreateMap() but that didn't work either.
I am injecting inside the service I am using:
private readonly IMapper _mapper;
public UserService(IMapper mapper)
{
_mapper = mapper;
}
And where the error is spit out is inside that service with this code: _mapper.Map<UserCustomerDto>(user)
I'm fairly new to dotnet core , and C# in general so any help would be greatly appreciated! Thank you and I hope this was informative enough to point me in the right direction.
UPDATE: When moving the Profile models to the same project as my Startup everything works fine. Now I just need to know how I can add reference to the other project containing my Profile models. Or maybe I can't? Would be nice to keep it in my Models project where the rest of my models are.