MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.38k stars 331 forks source link

How to use IRegister in asp.net 4.7.2 projects? #733

Open netty2019 opened 3 weeks ago

netty2019 commented 3 weeks ago

My project is asp.net 4.7.2 MVC, Mapster version 7.2.0

Configuring IRegister does not work

public class HjCollectDtlMapper : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.ForType<SaveDtlInput, HjCollectDtl>()
            .Map(u => u.IsManual, p => p.IsManual ? "Y" : "N");
    }
}
vchc commented 2 weeks ago

Do you scan for IRegister types at the startup?

TypeAdapterConfig.GlobalSettings.Scan(typeof(HjCollectDtlMapper).Assembly);

Or add them explicitly?

TypeAdapterConfig.GlobalSettings.Apply(new HjCollectDtlMapper());