Open it4factory opened 2 years ago
Any solutions to this? I'm trying something similar, to override a default mapping using .ForType.
I was of the impression, that I could override a property mapping using something like:
public class MyDocumentMapper
{
private readonly TypeAdapterConfig _typeAdapterConfig;
public MyDocumentMapper(TypeAdapterConfig typeAdapterConfig) // dependency injected
{
_typeAdapterConfig = typeAdapterConfig;
}
public ConvertedDocument ConvertDocument(Document document)
{
_typeAdapterConfig.ForType<Document, ConvertedDocument>()
.Map(dest => dest.Id, _ => "ID OVERRIDE");
return document.Adapt<ConvertedDocument>(_typeAdapterConfig);
}
}
However what happens is that my default rule in my IRegister implementation is used, and not the overriden mapping.
I wanted something that allowed me to define a set of default rules in an IRegister implementation, and then the posbility to override the config if necessary.
Is that possible?
I would like to have a default mapping used always and then I would like to be able to override it when required.
Here is the modified example code
Here is the result
Basically it adds new mappings but does not override the existing one.