I cannot get DI to work with mapperly. The documentation is not great so I may be misunderstanding. I’m look to convert automappers ConstructUsingServiceLocator
so that constructor parameters are populated.
I’ve set up Mapperly DI as in the docs like so:
//NOTE:Mapster = set up mapster with all Registers in all referenced assemblies
TypeAdapterConfig.GlobalSettings.RuleMap.Clear();
var config = TypeAdapterConfig.GlobalSettings;
config.Scan(AssemblyUtils.GetRunningAssemblies(typeof(Mapster.IRegister)));
config.RequireExplicitMapping = true;
//NOTE:Mapster - Add DI to mapster
//services.AddTransient<TypeAdapterConfig>(x => TypeAdapterConfig.GlobalSettings);
services.AddSingleton(config);
services.AddScoped<MapsterMapper.IMapper, ServiceMapper>();
and set up my mapping like so:
//Automapper: works, DI Params are populated
CreateMap<RegistrationCalfDTO, RegistrationCalfBO>(MemberList.Destination).ConstructUsingServiceLocator();
//Mapperly: DI params are all null
TypeAdapterConfig<RegistrationCalfDTO, RegistrationCalfBO>.NewConfig()
.ConstructUsing(x => MapContext.Current.GetService<RegistrationCalfBO>());
- Does Mapperly support construction Injection or is the lib just for added
IMapper
registration? - If it does, what am I missing
Thanks