How to use with a .Net 5 Web project and DI
MarkLFT opened this issue · 1 comments
I have a .Net 5 web project. AutoMapper is currently using DI and Profiles.
I am using services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); in the Startup class, and then a profiles class
public class EmailProfile : Profile { public EmailProfile() { // Source -> Target CreateMap<PersonDto, Person>(); } }
This is working great, but I would now like to use AutoMapper Collection, and I cannot see how I can do this, and I do not have an AutoMapper.Initialize anywhere, and even if I try to add one, it seems not to understand the Initialize method.
Can someone point me in the right direction of how to get the two libraries to work together in a .Net 5 web project?
Many thanks in advance.
There are more overloads of services.AddAutoMapper, for example in Startup
services.AddAutoMapper((sp, cfg) =>
{
cfg.AddCollectionMappers();
}, AppDomain.CurrentDomain.GetAssemblies());
or adding profiles manually
services.AddAutoMapper((sp, cfg) =>
{
cfg.AddCollectionMappers();
cfg.AddProfile<EmailProfile>()
}, Array.Empty<Assembly>());