having some trouble with adding profiles after some external assembly already added mapperconfiguration on the DI-setup.
first i just added some code to add the profiles
var mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile<DataMappingProfile>();
});
mapperConfiguration.AssertConfigurationIsValid();
services.AddSingleton<IMapper>(new Mapper(mapperConfiguration));
but then i overwrote some other mappingprofiles.
so i was thinking, i should try to add mine to the existing mappingconfiguration.
so i was going this way
var sp = services.BuildServiceProvider();
var autoMapper = sp.GetService<IMapper>();
var mapperConfiguration = autoMapper?.ConfigurationProvider as MapperConfiguration;
var configuration = new MapperConfigurationExpression();
configuration.AddProfile<LpisMappingProfile>();
if (mapperConfiguration == null)
{
mapperConfiguration = new MapperConfiguration(configuration);
}
else
{
//add the previous as well
//?? add this `configuration` ?
}
mapperConfiguration.AssertConfigurationIsValid();
services.AddSingleton<IMapper>(new Mapper(mapperConfiguration));
but i am a little stuck on the else
flow.
Any advice?
thnx!